knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-"
)
library(subsetr)

subsetr

Travis build status

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.

Examples

# 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)


jimhester/subsetr documentation built on May 29, 2019, 1:03 a.m.