Skip to content

Instantly share code, notes, and snippets.

View jimhester's full-sized avatar

Jim Hester jimhester

View GitHub Profile
jimhester /
Last active May 25, 2021 15:51
Static analysis for R packages
jimhester / lifecycle_linter.R
Last active March 22, 2021 17:02
Lint non-stable lifecycle functions used in your code.
db_lifecycles <- function(db) {
lifecycle_patterns <- paste0("(?:",
paste(collapse = "|",
jimhester / R-CMD-check.yaml
Created March 1, 2021 21:28
Highly annotated R GitHub Actions workflow
# We want to run this on all pushes on the 'main' branch, whether it is called main or master.
- main
- master
# We also want to run it on pull requests targetting the 'main' branch
- main

Q1. Are all the latest release versions of tidyverse and tidymodels packages already using cpp11?

All tidyverse packages that used Rcpp have been converted except for readxl and lubridate. We plan to finish converting the remainder of the packages in the next 6 months.

Q2. C++20 brings a lot of exciting features to the language, do you plan to also add a {cpp20} package too?

I agree! It is possible, but it would not be for at least 5 to 7 years from now, if ever. Compiler support and availablity often lags the language specifications significantly. However you can definitely use C++20 features with cpp11 in your package today if you like!

Q3. So writable:: is like not using const& in Rcpp?

jimhester /
Created July 16, 2020 17:53
script to compile R on macOS
# R recommends setting this to avoid issues with programs like sed:
export LANG=C
# Get version in major.minor format:
VERSION=`sed 's/\([0-9]*.[0-9]*\).[0-9]*.*/\1/' VERSION`
# Use version-dev as default folder target:
ld <- .getNamespaceInfo(asNamespace("datasets"), "lazydata")
df <- tibble::tibble(
name = names(ld),
data = map(name, ~ ld[[.x]]),
is_df = map_lgl(data, inherits, "data.frame")
) %>%
jimhester / Dockerfile
Created May 15, 2020 13:16
R package binary issue
FROM rstudio/r-base:3.6.3-bionic
RUN apt-get -qq update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y software-properties-common && \
add-apt-repository -y ppa:ubuntugis/ppa
Run apt-get install -y software-properties-common && \
add-apt-repository -y ppa:ubuntugis/ppa && \
apt-get update && \
jimhester /
Created April 9, 2020 13:41
Enable the use of Instruments from the command line with R

Enable use of Instruments from the command line with R

First, the time profiler template has a space in it, which breaks when called from R, so we need to add sym link to it that doesn't have a space.

cd /Applications/
sudo ln -s 'Time Profiler.tracetemplate' 'time-profiler.tracetemplate'
jimhester / dates.R
Last active January 2, 2020 17:23
Parsing dates with readr
the_dates <- c("2020-02-04", "04 February 2020", "2/4/20" , "4/2/20" , "04 Février 2020")
the_formats <- c("%Y-%m-%d", "%d %B %Y", "%m/%d/%y", "%d/%m/%y", "%d %B %Y")
the_locales <- list(locale("en"), locale("en"), locale("en"), locale("en"), locale("fr"))
list(the_dates, the_formats, the_locales),
function(date, format, locale) {
parse_date(date, format = format, locale = locale)