R: Data pronoun for tidy evaluation

tidyeval-data {rlang} | R Documentation

## Data pronoun for tidy evaluation

### Description

This pronoun allows you to be explicit when you refer to an object inside the data. Referring to the `.data` pronoun rather than to the original data frame has several advantages:

- It makes it easy to refer to column names stored as strings. If `var` contains the column `"height"`, the pronoun will subset that column:

      var <- "height"
      dplyr::summarise(df, mean(.data[[var]]))

  The index variable `var` is unquoted, which ensures a column named `var` in the data frame cannot mask it. This makes the pronoun safe to use in functions and packages.

- Sometimes a computation is not about the whole data but about a subset. For example if you supply a grouped data frame to a dplyr verb, the `.data` pronoun contains the group subset.

- It lets dplyr know that you're referring to a column from the data which is helpful to generate correct queries when the source is a database.

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

### Usage

    .data

[Package rlang version 0.4.2 Index]