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
app <- ambiorix::Ambiorix$new() | |
app$post("/process", function(req, res) { | |
body <- yyjsonr::read_json_raw(req$rook.input$read()) | |
msg <- sprintf( | |
"Hello, %s! Your age is %i, and your email is %s.", | |
body[["name"]], body[["age"]], body[["email"]] | |
) | |
res$json(list(message = msg, status = "success")) | |
}) |
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
log <- tempfile(fileext = ".log") | |
con <- file(log, open = "a") | |
addTaskCallback( | |
function(expr, value, ok, visible) { | |
if (rlang::is_condition(value)) { | |
write("Found a condition!!!!", con, append = TRUE) | |
} | |
if (visible) { | |
msg <- sprintf("[%sZ] > %s", format(Sys.time()), format(expr)) |
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(sfdep) | |
library(dplyr) | |
library(spdep) | |
guerry_nb |> | |
reframe(across(where(is.numeric), \(.x) broom::tidy(global_moran_perm(.x, nb, wt)))) |> | |
tidyr::pivot_longer(everything()) |> | |
tidyr::unnest(value) | |
moran_all <- function(.data, vars, nb_col = "nb", wt_col = "wt") { |
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
use serde::{Deserialize, Serialize}; | |
use std::collections::HashMap; | |
use std::fs::File; | |
use std::io::BufReader; | |
use std::path::Path; | |
#[derive(Debug, Clone, Serialize, Deserialize)] | |
#[serde(rename_all = "PascalCase")] | |
pub struct RenvLock { | |
pub r: RenvRVersion, |
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
# Original function | |
read_swm <- function(file) { | |
con <- file(file, "rb") | |
header <- NULL | |
while(TRUE) { | |
r <- readBin(con, "raw", size=1L, n=1, endian="little") | |
if (r == charToRaw("\n")) break | |
else header <- c(header, r) | |
} | |
cheader <- rawToChar(header) |
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" |
NewerOlder