Skip to content

Instantly share code, notes, and snippets.

View DavisVaughan's full-sized avatar

Davis Vaughan DavisVaughan

View GitHub Profile
@DavisVaughan
DavisVaughan / recode-values.R
Created February 20, 2026 13:33
recode-values
library(dplyr)
likert <- tibble(
score = c(1, 2, 3, 4, 5, 2, 3, 1, 4)
)
# Typical `case_when()` solution
likert |>
mutate(
category = case_when(
@DavisVaughan
DavisVaughan / replace-values.R
Created February 20, 2026 13:50
replace-values
# `replace_values()` is a swiss army knife!
library(dplyr)
state <- c("NC", "NY", "CA", NA, "NY", "Unknown", NA, "NotRecorded")
state
# ------------------------------------------------------------------------------
# Replace missing values with a constant
@DavisVaughan
DavisVaughan / filter-out.R
Created February 20, 2026 13:55
filter-out
# Why filter_out?
library(dplyr)
patients <- tibble(
name = c("Anne", "Mark", "Sarah", "Davis", "Max", "Derek", "Tina"),
deceased = c(FALSE, TRUE, NA, TRUE, NA, FALSE, TRUE),
date = c(2005, 2010, NA, 2020, 2010, NA, NA)
)
@DavisVaughan
DavisVaughan / dplyr-revdep-original-plan.md
Created February 12, 2026 18:19
dplyr-revdep-original-plan.md

Reverse Dependency Fix Plan

Overview

This plan outlines an automated approach to fix reverse dependency (revdep) failures caused by breaking changes in an upstream R package. The goal is to create a first-pass fix for each affected package that can then be reviewed and submitted as pull requests.

Parameters

Before executing this plan, the following must be specified:

@DavisVaughan
DavisVaughan / breakerofchains.txt
Created July 11, 2025 12:32
breakerofchains positron
na
@DavisVaughan
DavisVaughan / all-except.R
Last active July 4, 2025 17:53
Subset for all except certain words / patterns using stringr?
library(stringr)
# I had something like this
bobs <- c("bob.txt", "bob.scn", "bob")
# I want to remove just the strings with "scn"
# Using: https://stackoverflow.com/questions/5556213/regex-to-match-everything-except-the-given-words-which-may-include-hyphens-dash
str_subset(bobs, "^(?:(?!scn).)*$")
#> [1] "bob.txt" "bob"
{"name":"AI_RetryError","reason":"maxRetriesExceeded","errors":[{"name":"AI_APICallError","url":"https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-pro-exp-03-25:streamGenerateContent?alt=sse","requestBodyValues":{"generationConfig":{"temperature":0},"contents":[{"role":"user","parts":[{"text":"Can you replace all %>% with |> in the R/ folder?"}]},{"role":"model","parts":[{"text":"Okay, I can help you with that. I will replace all occurrences of %>% with the base R pipe |> in all R files within the R/ folder.\n\nI will proceed with the following steps:\n1. Get a list of all files in the R/ directory.\n2. For each R file (.R or .r extension):\n a. Read the content of the file.\n b. Replace all instances of %>% with |>.\n c. Write the modified content back to the file.\n\nPlease confirm if you'd like me to proceed."}]},{"role":"user","parts":[{"text":"Confirm"}]},{"role":"model","parts":[{"text":"Okay, I will proceed with replacing %>% with |> in all R files within the R/ folder.\n\nFirst, I nee
@DavisVaughan
DavisVaughan / zed-share-screen.log
Created April 15, 2025 15:19
zed-share-screen.log
-------------------------------------
Translated Report (Full Report Below)
-------------------------------------
Process: zed [60700]
Path: /Applications/Zed.app/Contents/MacOS/zed
Identifier: dev.zed.Zed
Version: 0.181.8 (20250415.090846)
Code Type: ARM-64 (Native)
Parent Process: launchd [1]
@DavisVaughan
DavisVaughan / tidygraph.r
Last active December 1, 2024 16:56
Exploring finanicial binomial recombining trees with tidygraph
# SCROLL TO THE GITHUB COMMENT BELOW FOR THE FULL OUTPUT WITH IMAGES
# COPY AND PASTE THIS FOR EASY ACCESS TO REPRODUCIBLE CODE
# ------------------------------------------------------------------------------
library(tidygraph)
library(ggraph)
library(dplyr)
library(igraph)
library(tibble)
@DavisVaughan
DavisVaughan / full-ci-failure.txt
Created September 29, 2024 01:09
full-ci-failure-for-blog-post
Running `/home/runner/work/ark/ark/target/debug/deps/kernel-7a83330cb920019c kernel --nocapture`
running 1 test
[crates/ark/src/interface.rs:230:5] &r_home = "/usr/lib/R"
[crates/ark/src/sys/unix/interface.rs:59:9] home = "/usr/lib/R"
thread 'dummy_kernel' panicked at crates/ark/src/interface.rs:1678:5:
Suicide: unable to initialize the JIT
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'dummy_kernel' panicked at library/core/src/panicking.rs:221:5: