Skip to content

Instantly share code, notes, and snippets.

Jim Hester jimhester

Block or report user

Report or block jimhester

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
jimhester / dates.R
Last active Jan 2, 2020
Parsing dates with readr
View dates.R
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)
jimhester / gun-violence.R
Last active Nov 15, 2019
Gun Violence benchmark
View gun-violence.R
# It is generally better not to benchmark the print methods to avoid misleading
# results, also vroom is faster on this particular dataset than
# either readr or data.table
jimhester / gist:9ba97fb3a090c7c182db6effbfceca50
Created Oct 22, 2019
places we use `$message` in r-lib packages
View gist:9ba97fb3a090c7c182db6effbfceca50
callr/ #> $message msg$message if (methods::is(response, "error") || !is.null(response$message)) {
remotes/install-github.R: error_details <- json$parse(rawToChar(res$content))$message
remotes/install-github.R: response$message)
remotes/install-github.R: if (methods::is(response, "error") || !is.null(response$message)) {
remotes/install-github.R: response$message)
gh/R/gh_response.R: paste0("Message: ", res$message)
callr/R/utils.R: exp <- tryCatch(parse(text = "1+"), error = function(e) e$message)
callr/R/result.R: err[[2]]$message <- err[[2]]$message %||% "interrupt"
jimhester / previous_commands.R
Created Aug 30, 2019
Get the previous commands as a text string in RStudio
View previous_commands.R
# RStudio overrides `history()`, `loadhistory()` and `savehistory()`,
# so they work somewhat differently than on the console version of R.
# This saves the current history to a temporary file then reads the last
# line of it (or more depending on the `n` argument)
# It does not handle multi-line commands, which would be more tricky to handle...
previous_commands <- function(n = 1) {
tf <- tempfile()
jimhester / github_vs_gitlab.R
Created Aug 29, 2019
GitHub vs GitLab for most recent 1000 R package releases
View github_vs_gitlab.R
# Measure usage of GitHub vs GitLab in R packages. This likely undercounts both GitHub and GitLab,
# becuase not every package puts a link to the development repository in their URL or BugReports fields.
# remotes::install_github("r-hub/crandb")
last_1000 <- crandb::events(archivals = FALSE, limit = 1000)
has_url <- function(x, url) {
any(grepl(url, c(tolower(x$package$URL), tolower(x$package$BugReports)), fixed = TRUE))
View 0001-Avoid-using-eval-parse.patch
From c2808f4d0f20682d9185d0e68bd33fe98d2dc7c2 Mon Sep 17 00:00:00 2001
From: Jim Hester <>
Date: Mon, 22 Apr 2019 07:43:48 -0400
Subject: [PATCH] Avoid using eval-parse
R/factory.R | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/R/factory.R b/R/factory.R
jimhester / fix-fork-and-pr.R
Created Dec 13, 2018
Programmatically make a fix, fork and open a PR
View fix-fork-and-pr.R
me <- "jimhester"
title <- "Remove default assets"
branch_name <- "remove-default_assets"
search <- gh("GET /search/code", q = "default_assets user:tidyverse")
cp /c/Users/Administrator/RStudio/rarrow/ .
cp -r /c/Users/Administrator/RStudio/rarrow/tools .
cp /c/Users/Administrator/RStudio/rarrow/src/ src/
# Change version in to 0.11.0
## this assumes arrow is installed via `make install`
mkdir -p windows/arrow-0.11.0/lib/x64
cp -r /c/Program\ Files\ \(x86\)/arrow/include windows/arrow-0.11.0/
cp /c/Program\ Files\ \(x86\)/arrow/lib/libarrow.a windows/arrow-0.11.0/lib/x64/
View 12-startup-jims.R
# Open your R profile
# Hint: use the usethis package
# Change the default CRAN mirror
# Hint: The repos option takes a named list of repositories
# A good default repo is
options(repos = c(CRAN = ""))
# Change the default startup message to something using the cowsay package,


  • Have a look around the files here. Where are the R scripts? What are the directories data and figs for? Do the names and structure help you find things?
  • Open each R script, finish it, and run it. Remember to restart R as you go, so you are certain each file is complete, i.e. data flows through explicit write/read, not the global workspace.
    • R/01_write-installed-packages.R
    • R/02_wrangle-packages.R
    • R/03_barchart-packages-built.R
  • It's OK if you don't finish! We can keep working on this later.
  • If you finish quickly, write an R script to run the whole analysis and, perhaps, another script that does a make clean style reset.
You can’t perform that action at this time.