knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-" ) library(subsetr)
subsetr uses tidy evaluation principles developed in rlang to provide
subset.data.frame() and [.data.frame() methods which use tidy non-standard
evaluation.
For most cases they provide drop in replacements for the existing methods, but can also avoid repetitive subsetting code. Because rlang provides robust lexical scoping they are suitable for use in top level scripts, functions and packages.
# Most existing code will work identically mtcars[mtcars$hp > 250, "mpg"] # But you can also use NSE to make things simpler mtcars[hp > 250, mpg] # The `j` argument works the same as the `select` argument in `base::subset()`. mtcars[hp > 250, mpg:disp] mtcars[hp > 250, -mpg]
The subset() interface is identical, but it now can also work properly inside
all functions.
detach(package:subsetr) val <<- 400 f <- function(x, val) { lapply(x, subset, hp > val) } f(list(mtcars), 250) library(subsetr) f <- function(x, val) { lapply(x, subset, hp > val) } f(list(mtcars), 250)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.