cumsum_cut <- function(x, cuts) {
x[cuts-1] <- 0
res <- lapply(split(x, cumsum(x == 0)), \(.x) {
cumsum(.x)
}) |>
unlist() |>
unname()
n <- length(res)
to_fill <- numeric(n)
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(terra) | |
library(Matrix) | |
# create a sample raster | |
r <- rast(ncols=10, nrows=10, ext(0, 10, 0, 10)) | |
x <- 1:ncell(r) | |
values(r) <- x | |
# why is there NaN in here???? | |
adj_raw <- adjacent(r, 1:ncell(r), "queen") |
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(spdep) | |
n <- 25 | |
geo <- sf::st_make_grid( | |
cellsize = c(1, 1), | |
offset = c(0, 0), | |
n = n | |
) | |
# create contiguity neighbors for the grid |
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
str_replace_many <- function(string, ...) { | |
replacements <- rlang::list2(...) | |
patterns <- rlang::names2(replacements) | |
if (anyNA(patterns) || any(!nzchar(patterns))) { | |
cli::cli_abort("All arguments passed to {.arg ...} must be named") | |
} | |
for (pattern in replacements) { | |
rlang:::check_string(pattern, arg = pattern) | |
} |
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
[package] | |
name = "my-hands" | |
version = "0.1.0" | |
edition = "2021" | |
[dependencies] | |
rand = "0.8.5" | |
rand_distr = "0.4.3" |
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
# What do i want from an object oriented R class system? | |
# opt-in public immutability - neither. Accomplished with private property with active binding in R6 | |
# interior mutability - R6 | |
# type safety - S7 | |
# self-referential methods - R6 | |
# private methods don't have any type safety they can be whatever you want. | |
# immutables can only be set at creation and class doesn't matter | |
# Each .public & .private element must be named |
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
# remotes::install_github("simonpcouch/forested") | |
library(dplyr) | |
library(sfdep) | |
library(spdep) | |
trees <- forested::forested |> | |
sf::st_as_sf(coords = c("lon", "lat"), crs = 4326) | |
k <- ceiling(nrow(trees)^(1/3)) |
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
[package] | |
name = "testthat-cli" | |
version = "0.1.0" | |
edition = "2021" | |
[dependencies] | |
argh = "0.1.12" |
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
#' @export | |
new_schedule_builder <- function() { | |
builder <- list( | |
sec = "0", | |
min = "0", | |
hour = "0", | |
dom = "*", | |
month = "*", | |
dow = "*", | |
year = "*" |
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(dplyr) | |
library(tidyr) | |
library(ggplot2) | |
url <- "https://projects.fivethirtyeight.com/polls/president-general/2024/national/polls.json" | |
# read in the raw json path | |
polls_raw <- RcppSimdJson::fload(url) | |
# filter to the IDs that contain Harris |
NewerOlder