This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(shinyjs) | |
ui <- fluidPage( | |
useShinyjs(), | |
hidden( | |
textInput("my_input", label = "my_input", value = "Initial value") | |
), | |
textOutput("my_output"), | |
actionButton("my_js_button","Update from JavaScript"), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Preparations | |
pkgs <- c("tidyverse", "pRecipe", "giscoR", "terra", "rayshader", "patchwork") | |
rlang::check_installed(pkgs) | |
suppressPackageStartupMessages({ | |
invisible(lapply(pkgs, library, character.only = TRUE, quietly = TRUE)) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Dades per CCAA =============================================================== | |
library(tidyverse) | |
library(rvest) | |
theme_set(theme_minimal()) | |
older_year <- 2002 | |
region <- tibble( | |
slug = c("andalucia", "aragon", "asturias", "canarias", "cantabria", "castilla-leon", | |
"castilla-la-mancha", "cataluna", "ceuta", "melilla", "madrid", "valencia", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
x <- list(a = list(b = 1, c = NULL), d = NULL) | |
get_list_names <- \(x, y = c()){ | |
if (!is.null(names(x))){ | |
for (nm in names(x)) { | |
y <- get_list_names(x[[nm]], c(y, nm)) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Game of Life using {coro} generators in R | |
# Inspiration from Jack Diederich's Python implementation: https://gist.github.com/jhrr/2b5a60e9efcb573c9cc4 | |
library(tidyverse) | |
library(coro) | |
library(zeallot) | |
generate_neighbors <- generator(function(point) { | |
c(x, y) %<-% point | |
yield(c(x + 1, y)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# preallocates memory. | |
fmat <- function(n) { | |
res <- matrix(NA, n, n) | |
for (i in 1:n) { | |
res[i, ] <- runif(n) | |
} | |
res | |
} | |
# rbind each time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# R CMD BATCH --vanilla json-benchmark.R | |
output_dir <- setwd(here::here()) | |
grDevices::dev.set(1) | |
# simpleBenchmark | |
file <- system.file("jsonexamples", "twitter.json", package="RcppSimdJson") | |
jsontxt <- readLines(file) | |
res <- microbenchmark::microbenchmark( | |
jsonify = jsonify::validate_json(jsontxt), | |
jsonlite = jsonlite::validate(jsontxt), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# remove.packages(c("universe", "sfdep")) | |
rlang::check_installed("universe", action = \(pkg, ...) { | |
install.packages('universe', repos = c('https://ropensci.r-universe.dev', 'https://cloud.r-project.org')) | |
}) | |
universe::add("ropensci") | |
universe::add("josiahparry") | |
rlang::check_installed("sfdep") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
n <- 1000 | |
v <- 1:n | |
vector_c <- function(n) { | |
out <- c() | |
for (i in 1:n) { | |
out <- c(out, i) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "anomalies" | |
format: html | |
jupyter: python3 | |
editor_options: | |
chunk_output_type: console | |
--- | |
Install requisites: |
NewerOlder