Skip to content

Instantly share code, notes, and snippets.

@infotroph
infotroph / gist:1b666a6ad58f201bb901a5e19a6d8df2
Last active September 15, 2022 17:01
PEcAn docker stack on M1 Mac (POC version)
* built a local ARM tidyverse image (I did this in a tempdir)
- Dockerfile:
```
FROM rocker/r-ver:4.2.1
ENV S6_VERSION=v2.1.0.2
ENV RSTUDIO_VERSION=daily
ENV DEFAULT_USER=rstudio
ENV PANDOC_VERSION=default
ENV PATH=/usr/lib/rstudio-server/bin:$PATH
@infotroph
infotroph / gist:a37850c7cbaeb1b339df97ec7537e350
Created August 17, 2020 21:05
Scaling an 7-state RNG to uniform integers on an arbitrary range
# in R:
rng_7 <- function(n) {
sample(0:6, size = n, replace = TRUE)
}
scale_rng <- function(m, n) {
range <- n - m
n_digits <- ceiling(log10(range) / log10(7))
exponents <- seq(from = n_digits - 1, to = 0)
@infotroph
infotroph / actions-exercises.md
Last active March 4, 2020 12:56
GSoC self-assessment ideas for GitHub Actions

Self-assessment ideas: R package testing + GitHub Actions

If you're new to either GitHub Actions or to CI testing of R packages, here are some exercises that can help you get a sense what's involved so that you can write a well-informed proposal. These are not mandatory, and we won't ask to see the results.

Set up simple GitHub Actions checks on an R package

  1. Pick any R package on GitHub and fork it to your own account. It doesn’t matter who wrote the package or what it does, as long as it doesn’t yet have any Actions configured. If you prefer, you could make a new dummy package instead of forking one.
  2. Add a GitHub Actions workflow that performs package checks on every push. Verify that the build passes reliably.
@infotroph
infotroph / actions.md
Last active March 3, 2020 14:55
Adding GitHub Actions to PEcAn

Adding GitHub Actions to PEcAn: Background info for GSoC 2020 applicants

Chris Black (@infotroph), 2020-02-29

Context

PEcAn is mostly developed by scientists who are skilled at programming but whose main job is not to write software, but rather to answer questions about the world. Therefore when someone has written code that helped them answer a question, we want it to be as easy as possible for them to contribute it to PEcAn without spending undue time worrying about configuring their development toolchain.

> tribble(~"X0.0 cm", ~"X1.5 cm", 1, 2) %>%
+ pivot_longer(
+ cols = everything(),
+ names_pattern = "X([\\d.]+) cm",
+ names_ptypes = list(name=double()))
Error: Lossy cast from `x` <character> to `to` <double>.
Locations: 1
Run `rlang::last_error()` to see where the error occurred.
@infotroph
infotroph / gist:bafb1871a76cbcef20460fdbad3cca26
Created April 10, 2019 10:05
Why does touching a file mark it changed in diff-index but not status? And then why does status mark it unchanged for diff-index?
0> git init
Initialized empty Git repository in /Users/chrisb/git_test/.git/
0> echo "some\ncontent" >> foo.txt
0> git add .
0> git commit -m 'first'
[master (root-commit) 3e1a325] first
1 file changed, 2 insertions(+)
create mode 100644 foo.txt
0> git diff-index HEAD
0> touch foo.txt
@infotroph
infotroph / git-biggest-blobs.md
Last active February 14, 2019 20:44
Find the largest objects in a Git repository

So your Git repository is getting ungainly large. What's causing it? Are the problem files still being updated, or are they the deleted ghosts of old binaries?

git cat-file --batch-check --batch-all-objects --unordered \
  | sort --numeric-sort --key=3 \
  | tail -n10 \
  | xargs -L1 sh -c \
    'pth=`git describe --always $0`; \
 printf "%s %s %s %s\n" $0 $1 $2 $pth'
@infotroph
infotroph / gist:378bce83b589bf993b847e88e7566a14
Last active October 28, 2018 16:21
Filter all timepoints from uninteresting parameters

Have: several treatments measured across time, many parameters recorded

dat <- expand.grid(
	time = 1:3,
	trt = letters[1:2],
	param = LETTERS[1:3])
dat$value <- c(
	rep(1.0, 6), # A: constant, should drop
	rep(c(1.0, 1.5, 2.0), 2), # B: trts identical within days, should drop
@infotroph
infotroph / gist:4067c8371236baefdff7c4fe5e3150a1
Last active October 18, 2018 18:16
How prevalent is the practice of committing Rd files to Git?
# Do R packages on GitHub commit their Rd files?
# Searched all of GitHub for "RoxygenNote", ordered by recently indexed,
# clicked through on all DESCRIPTION files in first five pages of results,
# if a fork clicked through to source, if a source then
# checked whether man/ directory contains Rd files
pik-piam/madrat, n (Rd files are gitignored)
hemberg-lab/scfind, y
daewoooo/primatR, y
dleutnant/muasdown, y
# selflibrary/showsearch.R:
showsearch_lib <- function(){
print(search())
library(selflibrary)
print(search())
}
$ R -q -e 'selflibrary::showsearch_lib()' chrisb@morus:~/Desktop/selflibrary
> selflibrary::showsearch_lib()
[1] ".GlobalEnv" "package:stats" "package:graphics"