Skip to content

Instantly share code, notes, and snippets.

View hadley's full-sized avatar

Hadley Wickham hadley

View GitHub Profile

Registering handlers

The key C function that powers both tryCatch() and withCallingHandlers() is do_addCondHands(). It creates handler object with mkHandlerEntry() then stores in the handler stack for the current frame. (More precisely it writes to R_HandlerStack, a global variable that is an alias to c->handlerstack)

The five R arguments to do_addCondHands() are classes, handlers, parentenv, target, and calling. These are combined with a result object (a list of length 4, returned by the exiting handler to doTryCatch()) to create the handler objects which have five components:

  • The class, accessed with ENTRY_CLASS(e). A string given a class name; the handler will match all conditions that contain this component in their class vector.
library(tidyverse)
library(lubridate)
url1 <- "https://cran.rstudio.com/src/contrib/Meta/archive.rds"
url2 <- "https://cran.rstudio.com/src/contrib/Meta/current.rds"
if (!file.exists(basename(url1))) download.file(url1, basename(url1), quiet = TRUE)
if (!file.exists(basename(url2))) download.file(url2, basename(url2), quiet = TRUE)
archive <- readRDS("archive.rds")
@hadley
hadley / stuff.md
Created August 14, 2017 20:40
gist gist gist

Stuff and things

head of mtcars

head(mtcars)
@hadley
hadley / stuff.md
Created August 14, 2017 20:40
gist gist gist

Stuff and things

head of mtcars

head(mtcars)
@hadley
hadley / stuff.md
Created August 8, 2017 23:27
gist gist gist

Stuff and things

head of mtcars

head(mtcars)
@hadley
hadley / stuff.md
Created August 8, 2017 23:27
gist gist gist

Stuff and things

head of mtcars

head(mtcars)
@hadley
hadley / stuff.md
Created August 7, 2017 21:56
gist gist gist

Stuff and things

head of mtcars

head(mtcars)
@hadley
hadley / stuff.md
Created August 7, 2017 21:56
gist gist gist

Stuff and things

head of mtcars

head(mtcars)
@hadley
hadley / stuff.md
Created August 4, 2017 13:09
gist gist gist

Stuff and things

head of mtcars

head(mtcars)
@hadley
hadley / stuff.md
Created August 4, 2017 13:08
gist gist gist

Stuff and things

head of mtcars

head(mtcars)