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
# simple R6 class | |
Random <- R6::R6Class("Random", | |
active = list(draw = function() runif(1)) | |
) | |
# instantiate the class | |
rnd <- Random$new() | |
# this calls the function | |
val <- rnd$draw |
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(purrr) | |
library(tidyr) | |
library(tibble) | |
library(ggplot2) | |
library(tictoc) | |
library(ggthemes) | |
library(here) | |
edge_length <- function(x1, y1, x2, y2) { |
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
unpack_double <- function(x) { | |
binary <- numToBits(x) # little-endian binary representation | |
structure( | |
list( | |
sign = binary[64], # 1-bit sign | |
exponent = binary[63:53], # 11-bit exponent | |
mantissa = binary[52:1] # 52-bit mantissa | |
), | |
class = "unpacked_double" |
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
set.seed(1) | |
sample_values <- function(n, p_safe) { | |
val <- rep("safe", n) | |
val[runif(n) > p_safe] <- "UNSAFE\n" | |
return(val) | |
} | |
# the wild-caught data had this structure | |
old_df <- tibble::tibble( |
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(gert) | |
library(usethis) | |
create_git_repo <- function(path) { | |
cat(path, "\n") | |
d <- setwd(path) | |
on.exit(setwd(d)) | |
git_init() | |
use_git_ignore(usethis:::git_ignore_lines) |
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
if(interactive()) { | |
cat("\014") # clear screen | |
cli::cli_text("") | |
cli::cli_text(R.version$version.string) | |
cli::cli_text("") | |
cli::cli_alert_success( | |
paste0( |
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(tidyverse) | |
# make toy data ----------------------------------------------------------- | |
# column of n randomly sampled responses | |
likert_col <- function(n = 10) { | |
sample(7, size = 10, replace = TRUE) | |
} | |
# toy data |
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
# attach evil_shims if needed | |
if(!("evil_shims" %in% search())) { | |
attach(new.env(), name = "evil_shims", pos = 2) | |
} | |
# paste0 function appends an invisible utf8 character 10% of the time | |
# e.g., for(i in 1:100) print(paste0("a", "b") == "ab") | |
assign( | |
x = "paste0", |
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(tidyverse) | |
library(scales) | |
library(ambient) | |
heart_x <- function(angle) { | |
x <- (16 * sin(angle)^3)/17 | |
return(x - mean(x)) | |
} |
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
pop <- (ggthemes::canva_pal("Pop art"))(4) | |
turmite59::turmite59( | |
shade = "#000000", | |
file = "~/Desktop/pop_heart.png", | |
palette_n = 4, | |
palette_heart = pop, | |
palette_turmite = pop, | |
turmite_steps = 100000000, | |
turmite_stepsize = 1 | |
) |
NewerOlder