Skip to content

Instantly share code, notes, and snippets.

View jdblischak's full-sized avatar

John Blischak jdblischak

View GitHub Profile
@nanxstats
nanxstats / cleanup-rproj-projectid.R
Last active February 10, 2025 15:01
Remove ProjectId field added by RStudio from .Rproj files at R startup
# Remove ProjectID from .Rproj files if freshly added
local({
xfun <- requireNamespace("xfun", quietly = TRUE)
rproj_files <- list.files(pattern = "\\.Rproj$", full.names = TRUE)
if (!xfun || length(rproj_files) == 0L) return(invisible(NULL))
lapply(rproj_files, function(f) {
diff_cmd <- system(paste("git diff --", shQuote(f)), intern = TRUE)
diff_out <- tryCatch(diff_cmd, error = function(e) character(0))
@JosiahParry
JosiahParry / r67.R
Created September 7, 2024 16:24
Experimentation with R6 and S7 hybrid. Allows for the creation of mutable objects with type-safe properties as well as self-referential methods.
# What do i want from an object oriented R class system?
# opt-in public immutability - neither. Accomplished with private property with active binding in R6
# interior mutability - R6
# type safety - S7
# self-referential methods - R6
# private methods don't have any type safety they can be whatever you want.
# immutables can only be set at creation and class doesn't matter
# Each .public & .private element must be named
# Top-level
thefuck <- function(e = rlang::last_error()) {
stopifnot(rlang::is_call_simple(e$call))
if (grep("^unused argument", e$message)) {
fix_unused_arg(e)
}
# ... more cases
}
# Internal methods
@defuneste
defuneste / mastodon_posit_conf.md
Last active August 21, 2024 17:30
list of mastodon users fromposit conf 2024
@nanxstats
nanxstats / simtrial-10k.tsv
Last active November 16, 2023 06:19
simtrial backend benchmark sketch
n 1 2 4 8 16
dplyr 5093.77 2671.44 1447.21 810.42 446.06
data.table 1336.79 677.94 364.5 217.75 143.95
@nanxstats
nanxstats / gsDesign-gource.sh
Created October 28, 2022 02:13
Shell commands to generate version control visualization video for gsDesign using gource
# Clone repo
git clone https://github.com/keaven/gsDesign.git
cd gsDesign
# Run gource - this will generate a 411GB ppm file
gource -3840x2160 --seconds-per-day 0.1 --auto-skip-seconds 0.01 --file-idle-time 0 --font-size 34 --key --logo man/figures/logo.png -o gsDesign.ppm
# Convert ppm to mp4
ffmpeg -y -r 60 -f image2pipe -vcodec ppm -i gsDesign.ppm -vcodec libx264 -preset medium -pix_fmt yuv420p -crf 1 -threads 0 -bf 0 gsDesign.mp4
# Merge audio to video
ffmpeg -i gsDesign.mp4 -i music.mp3 -c:v copy -c:a aac output.mp4
# Recommended by YouTube
data(diamonds, package = "ggplot2")
# Most straightforward
diamonds$ppc <- diamonds$price / diamonds$carat
# Avoid repeating diamonds
diamonds$ppc <- with(diamonds, price / carat)
# The inspiration for dplyr's mutate
diamonds <- transform(diamonds, ppc = price / carat)
@jokergoo
jokergoo / r_pkg_downloads.R
Created October 2, 2022 15:07
Number of downloads from CRAN/Bioc/conda
library(rvest)
library(jsonlite)
downloads_from_conda = function(pkg) {
x = read_html(paste0("https://anaconda.org/search?q=r-", pkg))
tb = html_nodes(x, "table") %>% html_table()
if(length(tb) > 0) {
tb = tb[[1]]
sum(tb[, 2])
} else {
0
@wviechtb
wviechtb / output.txt
Created May 4, 2022 09:23
Benchmark comparison of for-loops versus apply()/sapply() in 3 different versions of R (2.5.0, 3.0.0, 4.2.0)
> ############################################################################
>
> # A comparison of for-loops versus apply() and sapply() for 1) computing the
> # row means in a matrix and 2) for computing the means of all elements in a
> # list. For task 1), we can also examine the performance of rowMeans() as a
> # specialized / vectorized function and for task 2), we can also compare
> # sapply() with vapply() (note: vapply() was added in version R-2.12.0). Also,
> # for the for-loop, we can examine what the impact is of pre-allocating the
> # vector in which to store the results versus 'growing' the vector in each
> # iteration.
@ernstki
ernstki / getsnpcoords
Last active April 18, 2022 19:24
Fetch SNP coordinates from the UCSC MySQL server
#!/usr/bin/env bash
#
# Script to query UCSC MySQL server for SNP coordinates (but could easily be
# repurposed to query any arbitrary database/table)
#
# Author: Kevin Ernst
# Date: 2 March 2019; updated 30 August 2021
# Source: https://gist.github.com/ernstki/91b427d6714cdd4dd6560e5b4fb961f4
# License: MIT
#