Quote While the Promise Is Hot!

October 18, 2018

Suppose we want to quote x when x is not NULL. The naive implementation would be like below. Here, y is for comparison. Do you understand why x and y are quoted differently? quote_x_and_y <- function(x, y) { if (is.null(x)) { stop("x is NULL!", call. = FALSE) } x <- rlang::enquo(x) y <- rlang::enquo(y) list(x, y) } x <- y <- 1 quote_x_and_y(x, y) #> [[1]] #> <quosure> #> expr: ^1 #> env: empty #> #> [[2]] #> <quosure> #> expr: ^y #> env: global This is because x is evaluated when is. ... Read more

geom_sf_text() and geom_sf_label() Are Coming!

October 10, 2018

ggplot2 v3.1.0 will be released soon (hopefully), so let me do a spoiler about a small feature I implemented, geom_sf_label() and geom_sf_text(). How can we add label/text with geom_sf()? geom_sf() is one of the most exciting features introduced in ggplot2 v3.0.0. It magically allows us to plot sf objects according to their geometries’ shapes (polygons, lines and points). But, for plotting them as some other shapes than the original ones, we cannot rely on geom_sf() so it needs a bit of data transformation beforehand. ... Read more