Skip to content

Instantly share code, notes, and snippets.

View MichaelChirico's full-sized avatar

Michael Chirico MichaelChirico

View GitHub Profile
@MichaelChirico
MichaelChirico / methods_load_unload.R
Last active November 16, 2025 02:48
Check load/unload loop for methods downstreams
cran_repo = "https://cloud.r-project.org"
bioc_repo = BiocManager::repositories()["BioCsoft"]
cran_db <- data.frame(available.packages(repos = cran_repo))
bioc_db <- data.frame(available.packages(repos = bioc_repo))
methods_importers <- function(db, skip) db |>
subset(
grepl("(^|[^\\w.])methods($|[^\\w.])", Imports, perl=TRUE),
"Package",
@MichaelChirico
MichaelChirico / methods_load_unload.R
Created November 7, 2025 15:38
{methods} load+unload loop test
db <- data.frame(available.packages())
methods_imports <- db |>
subset(grepl("(^|[^\\w.])methods($|[^\\w.])", Imports, perl=TRUE), "Package", drop=TRUE)
test_lib = '/media/WesternDigital3839/tmpCRAN'
# very slow, and requires some iteration to get SystemRequirements
install.packages(methods_imports, lib=test_lib)
@MichaelChirico
MichaelChirico / nfl_game_durations.R
Created October 28, 2025 16:18
Get NFL game durations
library(rvest)
library(xml2)
PFR_URL = 'https://www.pro-football-reference.com'
read_with_backoff = function(url, sleep = 0.1) {
tryCatch(read_html(url), error = function(.) {
Sys.sleep(sleep)
sleep = 2 * sleep
message(sprintf("Failed, retrying in %.2fs", sleep))
@MichaelChirico
MichaelChirico / svn-range-finder.sh
Last active September 30, 2025 20:36
Find range of SVN commits where a file matches a pattern
#!/bin/bash
# GENERATED BY GEMINI
# Configuration Variables
# The path to the file in the SVN repository
FILE_PATH="src/library/parallel/NAMESPACE"
# The pattern you are searching for (case-sensitive)
SEARCH_PATTERN="splitList"
# --- Script Logic ---
@MichaelChirico
MichaelChirico / github_pr_file_metadata.R
Last active July 2, 2025 16:44
Scrape GitHub PRs in a repo to see which files they touch
# INITIALLY GENERATED BY GEMINI
# PR File Scraper
#
# Description:
# This script inspects a local Git repository, identifies its GitHub remote,
# and fetches all open pull requests. It then compiles a data.frame
# where each row represents a file modified in a specific pull request,
# along with metadata about that PR.
#
@MichaelChirico
MichaelChirico / rcv_bootstrap.R
Created June 6, 2025 14:19
Code for running bootstraps of ranked-choice voting elections
library(data.table)
library(ggplot2)
# Downloaded from https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/AMK8PJ
dir="/media/michael/ab3f2700-872c-4b29-95f2-9a700166bc52/dataverse_files"
run_rcv_election = function(ballots) {
# TODO(michaelchirico): there should be a way to safely avoid a full copy, is it worth it?
ballots = copy(ballots[, .(rank, candidate)])
# _don't_ rely on ballots$voterid from input -- in bootstrap, under resampling, we will have
@MichaelChirico
MichaelChirico / rbind.fill_vs_bind_rows.R
Last active June 3, 2025 23:21
Comparing plyr::rbind.fill and dplyr::bind_rows()
# quick look sheet for comparing plyr::rbind.fill --> dplyr::bind_rows()
# NB: I am only interested in migrating rbind.fill-->bind_rows(), so
# features of bind_rows() absent from rbind.fill(), e.g. .id=, are not examined.
rbind.fill = plyr::rbind.fill
bind_rows = dplyr::bind_rows
DF1 = data.frame(a = 1, b = 2)
DF2 = data.frame(a = 1, b = 2)
all.equal(rbind.fill(DF1, DF2), bind_rows(DF1, DF2))
@MichaelChirico
MichaelChirico / h1_h2_h3_news.R
Created May 6, 2025 06:26
Demonstrate equivalence of h1/h2 and h2/h3 hierarchies for utils::news
news_fmt <- "%1$s My NEWS
%1$s# pkg 1.0.0 (2020-01-01)
%1$s## Categ 1
%1$s# pkg 0.4.0 (2019-01-01)
%1$s## Categ 1
@MichaelChirico
MichaelChirico / r_devel_path_cran_test.R
Last active August 18, 2024 07:16
r-devel CRAN sample
# Script to test a patched version of r-devel against a selection of CRAN packages
# Useful for detecting possible breaking changes by examining how changes affect actual packages
# Does not require a local CRAN mirror -- idea is to only test a small fraction of CRAN -->
# relatively small I/O cost of downloading the packages on the fly.
# This script is used for the patch here:
# https://github.com/r-devel/r-svn/pull/177
# https://bugs.r-project.org/show_bug.cgi?id=18782
# https://bugs.r-project.org/show_bug.cgi?id=17672
PACKAGES_TO_TEST = c(
@MichaelChirico
MichaelChirico / recommended_partial_issues.R
Last active April 25, 2024 06:43
Check all Recommended packages for partial matching issues