| title | format |
|---|---|
Merging R objects like dictionaries in R |
html |
Let's explore how to merge lists, enviroments or vectors like dictionaries in R.
pak::pak(c(
"purrr",
| # Reference: By Josh Goldstein from Dirk Eddelbuettel on https://mastodon.social/@eddelbuettel/116132645744985793 | |
| library(data.table) | |
| cw <- data.table(ChickWeight) | |
| # fmt: skip | |
| cw21 <- ( | |
| cw[Time %in% c(0, 21)] | |
| [, Weight := weight] | |
| [, Group := factor(paste0("Diet_", Diet))] |
| # pak::pak("r-lib/nanonext") | |
| library(nanonext) | |
| conns <- list() | |
| handlers <- list( | |
| handler_stream("/stream", | |
| on_request = function(conn, req) { | |
| conn$set_header("Content-Type", "application/x-ndjson") | |
| conns[[as.character(conn$id)]] <<- conn | |
| conn$send('{"status":"connected"}\n') |
| title | format |
|---|---|
Merging R objects like dictionaries in R |
html |
Let's explore how to merge lists, enviroments or vectors like dictionaries in R.
pak::pak(c(
"purrr",
| --- | |
| title: "Create and search image embeddings using torch, mobilenet v3, rchroma and R" | |
| --- | |
| Prepare torch, and mobilenet v3 embeddings. | |
| ```{r} | |
| if (!rlang::is_installed("torch")) { | |
| # https://torch.mlverse.org/docs/articles/installation#pre-built | |
| options(timeout = 90000) |
| { | |
| "lib": { | |
| "prefix": "lib", | |
| "body": "library(${1:package})", | |
| "description": "Attach an R package" | |
| }, | |
| "src": { | |
| "prefix": "src", | |
| "body": "source(\"${1:file.R}\")", | |
| "description": "Source an R file" |
| library(purrr) | |
| # The intial information | |
| elements <- tibble::tribble( | |
| ~key , ~values , | |
| "Barbie" , "shoes" , | |
| "Oppenheimer" , "history" | |
| ) | |
| # Aditional values we want to proces |
| library(rextendr) | |
| library(mirai) | |
| rextendr::rust_source( | |
| file = "rust/xymatch_loop.rs", | |
| module = "xymatch_loop", | |
| profile = "release" | |
| ) | |
| rextendr::rust_source( | |
| file = "rust/xymatch_binary.rs", | |
| module = "xymatch_binary", |
| library(S7) | |
| ScalarDouble <- new_class("ScalarDouble", | |
| properties = list(value = class_double), | |
| constructor = function(value) { | |
| stopifnot(is.double(value), length(value) == 1) | |
| new_object(ScalarDouble, value = value) | |
| } | |
| ) |
| stopifnot(requireNamespace("rlang")) | |
| rlang::check_installed("pak") | |
| pkgs <- rlang::chr( | |
| "tidymodels", | |
| "marginaleffects", | |
| "parameters", | |
| "modelbased", | |
| "dplyr", | |
| "stringr", | |
| "tibble", |