Skip to content

Instantly share code, notes, and snippets.

Chris Black infotroph

Block or report user

Report or block infotroph

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:8f6f294d5047dabe0d524724c64b2604
> 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 / gist:bafb1871a76cbcef20460fdbad3cca26
Created Apr 10, 2019
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?
View gist:bafb1871a76cbcef20460fdbad3cca26
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 /
Last active Feb 14, 2019
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 / gist:378bce83b589bf993b847e88e7566a14
Last active Oct 28, 2018
Filter all timepoints from uninteresting parameters
View gist:378bce83b589bf993b847e88e7566a14

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 / gist:4067c8371236baefdff7c4fe5e3150a1
Last active Oct 18, 2018
How prevalent is the practice of committing Rd files to Git?
View gist:4067c8371236baefdff7c4fe5e3150a1
# 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
View gist:54ded9fce054b9c2befc8360c547a044
# selflibrary/showsearch.R:
showsearch_lib <- function(){
$ R -q -e 'selflibrary::showsearch_lib()' chrisb@morus:~/Desktop/selflibrary
> selflibrary::showsearch_lib()
[1] ".GlobalEnv" "package:stats" "package:graphics"
infotroph / gist:bf522f5959a0ff709377919131bf23d8
Created Aug 20, 2018
R package installation errors inside parallel make
View gist:bf522f5959a0ff709377919131bf23d8
root@7c782f3c2892:~# cat Makefile
Rscript -e 'install.packages("getPass", type = "source")'
root@7c782f3c2892:~# make
Rscript -e 'install.packages("getPass", type = "source")'
Installing package into '/usr/local/lib/R/site-library'
(as 'lib' is unspecified)
trying URL ''
Content type 'application/x-gzip' length 252439 bytes (246 KB)
infotroph /
Created Jun 28, 2018
Investigating dependencies for a large suite of tightly-coupled, non-CRAN R packages

What software do I need to have installed for a working copy of PEcAn?

Great question. Let's find out, with two big caveats.

  1. This approach will find components formally required by one or more of the PEcAn R packages. It will not tell us what dependencies are missing from the package descriptions, nor about any of PEcAn's non-R dependencies -- notably, the list it produces will not contain Postgres or any of the components of Bety. But we will get a list of the system libraries needed by each R package (e.g. RCurl depends on your OS's libcurl), at least to the extent that the packages declare them.

  2. Ironically, it only works on a system that already has all of PEcAn installed. If your machine is already in dependency hell, this probably won't help because R won't know how to find and recursively check the dependencies it doesn't yet have. But with some refinements, this approach could probably autogenerate a list of dependencies so that we can, say, mention new ones in the changelog.

For th

View attempted bety load: OS X
# OS X 10.13.4, Postgres 10.4
0> curl -o bety.sql.gz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 167M 100 167M 0 0 7790k 0 0:00:21 0:00:21 --:--:-- 8289k
View gist:19513e684c97b576e24c8b1058b082ee
# local df works as expected with or without .data
mtcars %>% select(mpg) %>% filter(mpg > 33)
# mpg
# 1 33.9
mtcars %>% select(.data$mpg) %>% filter(.data$mpg > 33)
# mpg
# 1 33.9
You can’t perform that action at this time.