This file contains hidden or 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 hidden or 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
# show all the function names in a given set of R scripts | |
function_definitions = function(files) { | |
purrr:::map(files, function_definitions_script) |> | |
purrr::list_rbind() | |
} | |
function_definitions_script = function(file) { | |
text = brio::read_lines(file) |> | |
paste(collapse = "\n") | |
This file contains hidden or 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(httr2) | |
library(purrr) | |
endpoint <- "https://models.inference.ai.azure.com" | |
token <- Sys.getenv("github_token") | |
model <- "gpt-4o-mini" | |
system <- list( | |
"role" = "system", | |
"content" = "You are a helpful assistant." |
This file contains hidden or 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
#[macro_export] | |
macro_rules! tw { | |
// Base case: when there are no tokens left, return an empty string. | |
() => (String::new()); | |
// New case: handle static string literals | |
($static:literal ; $($rest:tt)*) => {{ | |
let mut class = String::from($static); | |
let rest_classes = tw!($($rest)*); | |
if !rest_classes.is_empty() { |
This file contains hidden or 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(shiny) | |
library(shinyjs) | |
ui <- fluidPage( | |
useShinyjs(), | |
hidden( | |
textInput("my_input", label = "my_input", value = "Initial value") | |
), | |
textOutput("my_output"), | |
actionButton("my_js_button","Update from JavaScript"), |
This file contains hidden or 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
#![feature(portable_simd)] | |
#![feature(array_chunks)] | |
#[extendr] | |
fn vacc(age: &[f64], female: &[u8], ily: &[f64]) -> Vec<f64> { | |
age.array_chunks::<4>() | |
.map(|&a| f64x4::from_array(a)) | |
.zip(female.array_chunks::<4>().map(|&f| u8x4::from_array(f))) | |
.zip(ily.array_chunks::<4>().map(|&i| f64x4::from_array(i))) | |
.map(|((a, f), i)| { |
This file contains hidden or 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
// save to windows-user directory | |
linters: with_defaults(object_name_linter = NULL, | |
object_length_linter(50), | |
commented_code_linter = NULL, | |
object_usage_linter = NULL, | |
line_length_linter(120), | |
cyclocomp_linter = cyclocomp_linter(50)) |
This file contains hidden or 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
new_render <- function(dir = "readings") { | |
old_names <- fs::dir_ls(dir) | |
new_names <- basename(old_names) | |
if (any(new_names %in% fs::dir_ls())) { | |
stop("Files in folders can not have same name as main files") | |
} |
This file contains hidden or 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
require("sf") | |
require("dplyr") | |
require("hexbin") | |
# Linux libertine font "sf", converted to path with Inkscape, | |
# added points between existing points 2 times, then turned all segments into straight lines. | |
# Saved as SVG with absolute coordinates (Preferences > SVG Output > Path Data). | |
# Loaded coords from SVG source code, remove letters from start and end, and replace " " with "," | |
coords_f <- c(218.1169,163.46992,215.56952,177.96334,213.51976,189.84421,211.82546,200.33884,210.34442,210.67351,208.24728,226.35176,205.51032,243.54066,201.92029,259.27223,197.26391,270.57846,195.45112,272.90665,193.28288,274.70167,190.97247,275.85687,188.73314,276.26564,187.03291,276.03164,185.79476,275.38887,184.84097,274.42619,183.99382,273.23248,182.45947,271.13533,180.24976,269.10927,177.54243,267.58084,174.51519,266.97658,171.25987,267.58973,169.08867,269.18036,167.87718,271.37526,167.501,273.8012,168.44294,277.0032,171.48203,279.79643,176.93817,281.77214,185.13126,282.52154,191.01986,281.80176,196.83737,279.60686,202.29944, |
This file contains hidden or 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
#' Source specific lines in an R file | |
#' | |
#' @param file character string with the path to the file to source. | |
#' @param lines numeric vector of lines to source in \code{file}. | |
source_lines <- function(file, lines){ | |
source(textConnection(readLines(file)[lines])) | |
} |
NewerOlder