Skip to content

Commit 4004384

Browse files
committed
Document use of objects in the calling environment, closes #949
1 parent af03d67 commit 4004384

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

R/tibble.R

+11-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@
3131
#' Arguments are evaluated sequentially.
3232
#' You can refer to previously created elements directly or using the [.data]
3333
#' pronoun.
34-
#' An existing `.data` pronoun, provided e.g. inside [dplyr::mutate()],
35-
#' is not available.
34+
#' To refer explicitly to objects in the calling environment, use [`!!`] or
35+
#' [.env], e.g. `!!.data` or `.env$.data` for the special case of an object
36+
#' named `.data`.
3637
#' @param .rows The number of rows, useful to create a 0-column tibble or
3738
#' just as an additional check.
3839
#' @param .name_repair Treatment of problematic column names:
@@ -143,6 +144,14 @@
143144
#' # You can splice-unquote a list of quosures and expressions:
144145
#' tibble(!!! list(x = rlang::quo(1:10), y = quote(x * 2)))
145146
#'
147+
#' # Use .data, .env and !! to refer explicitly to columns or outside objects
148+
#' a <- 1
149+
#' tibble(a = 2, b = a)
150+
#' tibble(a = 2, b = .data$a)
151+
#' tibble(a = 2, b = .env$a)
152+
#' tibble(a = 2, b = !!a)
153+
#' try(tibble(a = 2, b = .env$bogus))
154+
#' try(tibble(a = 2, b = !!bogus))
146155
tibble <- function(...,
147156
.rows = NULL,
148157
.name_repair = c("check_unique", "unique", "universal", "minimal")) {

man/lst.Rd

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/tibble.Rd

+11-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)