library(tidyverse)
# example lagging code
n <- 100
grid_cov <- expand_grid(
covariates = c("rainfall", "temperature"),
years = 2000:2022,
row = seq_len(n)
) |>
# example lagging code
library(tidyverse)
n <- 100
grid_cov <- expand_grid(
covariates = c("rainfall", "temperature"),
years = 2000:2022,
row = seq_len(n)
elev <- terra::rast(system.file("ex", "elev.tif", package = "terra"))
elev
#> class : SpatRaster
#> dimensions : 90, 95, 1 (nrow, ncol, nlyr)
#> resolution : 0.008333333, 0.008333333 (x, y)
#> extent : 5.741667, 6.533333, 49.44167, 50.19167 (xmin, xmax, ymin, ymax)
#> coord. ref. : lon/lat WGS 84 (EPSG:4326)
#> source : elev.tif
#> name : elevation
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
compare_git_commits <- function(repo, sha1, sha2){ | |
# https://github.com/github-linguist/linguist/compare/f75c570..3391dcc | |
glue::glue("{repo}/compare/{sha1}..{sha2}") | |
} | |
compare_greta_commits <- function(sha1, sha2){ | |
compare_git_commits(repo = "https://github.com/greta-dev/greta/", | |
sha1 = sha1, | |
sha2 = sha2) | |
} |
library(distributional)
library(tidyverse)
tibble(
dist = c(dist_normal(0,1), dist_normal(4,7), dist_normal(2,8))
) |>
mutate(
sample = generate(dist, 10),
params = parameters(dist)
)
# General process would be:
# 1. Simulate a wishart draw x with rWish()
# 2. Transform x to the equivalent free_state, using the bijector but running it in reverse
# 3. Run the log_prob() function on free_state
# 4. Run dWish(..., log = TRUE) on x, and compare with result of step 3
devtools::load_all(".")
#> ℹ Loading greta
#> ℹ Initialising python and checking dependencies, this may take a moment.
#>
library(tidyverse)
txt <- "day 0 dis influenza host 1111 age 19.19day 0 dis influenza host 2222 age 5.55day 0 dis influenza host 333 age 11.11"
# age has to have two \\d+ as it abuts the next column, "day"
pattern <- "day (\\w+) dis (\\w+) host (\\w+) age (\\d+\\.\\d+)"
# Use str_match_all to extract all occurrences
matches <- str_match_all(txt, pattern)[[1]]
Just to build on https://gist.github.com/DavisVaughan/294b6934ae1f291634534ac952dcfa02, here is what we did in order to get this to work with Devel R.
We created a C file, named zzz.c
in src/main/zzz.c
, and also had to have the following header files in the below order. Then we also had to add a line to the (already existing) makefile, Makefile.in
in src/main/Makefile.in
, where we added a line zzz.c
under SOURCES_C = \
.
Then we did the regular debug stuff:
Sys.getpid()
- Copy pid into LLDB debugger
- Add breakpoint in C code
- Run code to trigger breakpoints
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
sample.int <- function(n, size = n, replace = FALSE, prob = NULL, | |
prob_method = c("sequential", "marginal", "poisson"), | |
useHash = (n > 1e7 && !replace && is.null(prob) && size <= n/2)){ | |
stopifnot(length(n) == 1L) | |
replace_or_no_prob <- is.null(prob) || replace | |
if (replace_or_no_prob){ | |
size <- size %||% n | |
if (useHash) { | |
## will work with size > n/2 but may be slow. |
NewerOlder