Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

tidyeval-data

Data pronouns for tidy evaluation


Description

These pronouns allow you to be explicit about where to find objects when programming with data masked functions.

m <- 10
mtcars %>% mutate(disp = .data$disp * .env$m)
  • .data retrieves data-variables from the data frame.

  • .env retrieves env-variables from the environment.

Because the lookup is explicit, there is no ambiguity between both kinds of variables. Compare:

disp <- 10
mtcars %>% mutate(disp = .data$disp * .env$disp)
mtcars %>% mutate(disp = disp * disp)

The .data object exported from rlang is also useful to import in your package namespace to avoid a R CMD check note when referring to objects from the data mask.

Note that .data is only a pronoun, it is not a real data frame. This means that you can't take its names or map a function over the contents of .data. Similarly, .env is not an actual R environment. For instance, it doesn't have a parent and the subsetting operators behave differently.

Usage

.data

.env

rlang

Functions for Base Types and Core R and 'Tidyverse' Features

v0.4.11
MIT + file LICENSE
Authors
Lionel Henry [aut, cre], Hadley Wickham [aut], mikefc [cph] (Hash implementation based on Mike's xxhashlite), Yann Collet [cph] (Author of the embedded xxHash library), RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.