View check_installed_universe_packages.R
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") |
View loops-are-not-that-bad.R
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) | |
} |
View anomalies.qmd
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: |
View anomalies.R
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
# GAM model with a local smoother | |
library(tidyverse) | |
set.seed(2) | |
elapsed <- arima.sim(model = list(order = c(0, 1, 0)), n=200) + 20 | |
elapsed <- pmax(elapsed, 1) | |
data <- tibble( | |
x = 1:201, | |
elapsed = elapsed | |
) | |
plot(data) |
View base-r-summarise.R
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
# Single grouping in base R: Multiple functions | |
library(dplyr, warn.conflicts = FALSE) | |
expected_output <- mtcars %>% | |
group_by(cyl) %>% | |
summarise(mean = mean(disp), n = n()) %>% | |
as.data.frame() | |
expected_output | |
by <- c("cyl") |
View stacked_rasters.vrt
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
<VRTDataset rasterXSize="10" rasterYSize="10"> | |
<SRS dataAxisToSRSAxisMapping="2,1">GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]</SRS> | |
<GeoTransform> 0.0000000000000000e+00, 1.0000000000000000e+00, 0.0000000000000000e+00, 9.0000000000000000e+01, 0.0000000000000000e+00, -1.8000000000000000e+01</GeoTransform> | |
<VRTRasterBand dataType="Float32" band="1"> | |
<NoDataValue>nan</NoDataValue> | |
<ColorInterp>Gray</ColorInterp> | |
<ComplexSource> | |
<SourceFilename relativeToVRT="0">rasters/raster.tif</SourceFilename> | |
<SourceBand>1</SourceBand> | |
<SourceProperties RasterXSize="10" RasterYSize="10" DataType="Float32" BlockXSize="10" BlockYSize="10" /> |
View combine_multylayered_raster_vtr.R
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
# combine_multylayered_raster_vtr.R: Combine multilayered_raster vtr using terra package | |
library(terra) | |
test <- TRUE | |
test_create_vrt_from_multilayers <- function() { | |
raster_objects <- create_multiplayered_rasters() | |
print(class(raster_objects[[1]]) == "SpatRaster") | |
print(class(raster_objects[[2]]) == "SpatRaster") | |
out <- create_vrt_from_multilayers(raster_objects) | |
print(out) |
View tasa_paro.R
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) | |
economics_raw <- read_csv("https://gist.githubusercontent.com/jrosell/cf35e54a70914a3b23946c0a0d3a2cee/raw/47e52b910ecb23c3c7a8c549c9fd277797bd9970/economics_long.csv") | |
print(economics_raw, n = 5) | |
glimpse(economics_raw) | |
economics_raw %>% | |
glimpse(x = .) |
View economics_long.csv
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
date | variable | value | value01 | |
---|---|---|---|---|
1967-07-01 | pce | 506.7 | 0 | |
1967-08-01 | pce | 509.8 | 2.652497197765077e-4 | |
1967-09-01 | pce | 515.6 | 7.615233890357775e-4 | |
1967-10-01 | pce | 512.2 | 4.7060434153896666e-4 | |
1967-11-01 | pce | 517.4 | 9.155393553576157e-4 | |
1967-12-01 | pce | 525.1 | 0.001574385433512166 | |
1968-01-01 | pce | 530.9 | 0.002070659102771431 | |
1968-02-01 | pce | 533.6 | 0.002301683052254198 | |
1968-03-01 | pce | 544.3 | 0.003217222407611809 |
View pak.R
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
# install.packages("pak") | |
stopifnot( | |
'{pak} no está instalado. Por favor, ejecuta install.packages("pak") en la consola y vuelve a intentarlo.' = | |
sum("pak" == row.names(installed.packages())) == 1 | |
) | |
instalar <- setdiff( | |
c("ggplot2", "dplyr", "tidyr", "readr", "purrr", "tibble", "stringr", "forcats", "lubridate", "magrittr", "tidyverse"), | |
rownames(installed.packages()) | |
) |
NewerOlder