You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: vignettes/ggplot2-in-packages.Rmd
+8Lines changed: 8 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -79,6 +79,8 @@ There are three situations in which you will encounter this problem:
79
79
- You have the column name as a character vector.
80
80
- The user specifies the column name or expression, and you want your function to use the same kind of non-standard evaluation used by `aes()` and `vars()`.
81
81
82
+
### Mapping is known in advance
83
+
82
84
If you already know the mapping in advance (like the above example) you should use the `.data` pronoun from [rlang](https://rlang.r-lib.org/) to make it explicit that you are referring to the `drv` in the layer data and not some other variable named `drv` (which may or may not exist elsewhere). To avoid a similar note from the CMD check about `.data`, use `#' @importFrom rlang .data` in any roxygen code block (typically this should be in the package documentation as generated by `usethis::use_package_doc()`).
83
85
84
86
```{r}
@@ -89,6 +91,8 @@ mpg_drv_summary <- function() {
89
91
}
90
92
```
91
93
94
+
### Character columns
95
+
92
96
If you have the column name as a character vector (e.g., `col = "drv"`), use `.data[[col]]`:
If the column name or expression is supplied by the user, you can also pass it to `aes()` or `vars()` using `{{ col }}`. This tidy eval operator captures the expression supplied by the user and forwards it to another tidy eval-enabled function such as `aes()` or `vars()`.
0 commit comments