Skip to content

Instantly share code, notes, and snippets.

@EmilHvitfeldt
EmilHvitfeldt / evolutiions.csv
Created April 3, 2025 19:29
most pokemon evolutions
name stage family
bulbasaur 1 1
ivysaur 2 1
venusaur 3 1
charmander 1 2
charmeleon 2 2
charizard 3 2
squirtle 1 3
wartortle 2 3
blastoise 3 3
@EmilHvitfeldt
EmilHvitfeldt / revealjs-scss-theming-prompt.md
Last active November 20, 2024 14:21
revealjs-scss-theming-prompt.md

Create sass style sheet for use in quarto revealjs slides

You are a terse assistant designed to help quarto users in styling revealjs slides. Respond with only the modified code with no backticks or newlines around the response. Add fonts when they fit with the theme.

Use sass variables to define colors

use human readable sass variables to define colors and use those variables instead of specifying colors inline. Prefix these color variables with $theme-.

// before
@EmilHvitfeldt
EmilHvitfeldt / test-lightgbm.md
Last active November 9, 2024 19:30
figure out if we are doing something wrong with lightgbm
library(tidymodels)
library(embed)
library(bonsai)

train_set <- ames |>
  slice_sample(n = 50000, replace = TRUE) |>
  rename(survey_target = Street)

lgb_model_recipe <- recipe(survey_target ~ ., train_set) |> 
@EmilHvitfeldt
EmilHvitfeldt / add-gha-hard.R
Last active October 15, 2024 20:13
Add R CMD Check hard GHA
src_pth <- "https://raw.githubusercontent.com/r-lib/actions/refs/heads/v2-branch/examples/check-no-suggests.yaml"
tmp_pth <- tempfile()
download.file(pth, destfile = tmp_pth)
hard_check <- readLines(tmp_pth)
hard_check <-
gsub("name: check-no-suggests.yaml",
"name: R-CMD-check-hard.yaml",
hard_check,
fixed = TRUE)
@EmilHvitfeldt
EmilHvitfeldt / count-message-warnings-errors.R
Created October 10, 2024 19:17
Count all message, warnings, and errors in R package
counter <- function(fun) {
function(x) {
r_files <- fs::dir_ls(fs::path(x, "R"))
excludes <- stringr::str_detect(
basename(r_files),
"^(deprecated|import)-",
negate = TRUE
)
r_files[excludes] |>
purrr::map(readLines) |>
@EmilHvitfeldt
EmilHvitfeldt / untested-cli-in-r-package.R
Last active October 20, 2024 16:51
find untested cli code in R package
library(tidyverse)
# https://github.com/r-lib/covr/issues/482
res_tbl <- devtools::test_coverage() |>
purrr::map(~tibble(
value = if_else(is.null(.x$value), NA, .x$value),
code = as.character(.x$srcref)
)) |>
purrr::list_rbind(names_to = "file")
@EmilHvitfeldt
EmilHvitfeldt / sparse-matrix-output-step_dummy.md
Created May 2, 2024 05:00
sparse matrix output step_dummy
library(recipes)
library(nycflights13)


# rec <- recipe(dep_delay ~ carrier + tailnum + origin + dest, data = flights) |>
rec <- recipe(dep_delay ~ tailnum, data = flights[1:100000, ]) |>
  step_dummy(all_nominal_predictors())

options("recipes.sparse" = FALSE)
@EmilHvitfeldt
EmilHvitfeldt / sparse-step_dummy.md
Created May 2, 2024 04:32
sparse step_dummy progress
library(recipes)
library(nycflights13)

rec <- recipe(dep_delay ~ carrier + tailnum + dest + origin, data = flights) |>
  step_dummy(all_nominal_predictors())

options("recipes.sparse" = FALSE)

system.time({
library(dplyr)
library(purrr)
library(sparsevctrs)

# Dense -----------------------------------------------------
dense_vec <- function(x, len) {
  res <- numeric(len)
  res[x] <- x
  res
@EmilHvitfeldt
EmilHvitfeldt / profmem-sparse-textrecipes.md
Created April 17, 2024 16:38
profmem of sparse vs textrecipes
library(tidymodels)
library(textrecipes)
library(friends)

library(profmem)

p <- profmem({
preped_rec <- recipe(season ~ text, data = friends) %>%
  step_tokenize(text) %>%