remove_tmp_vars | R Documentation |
Remove All Temporary Variables Created Within the Current Function Environment
remove_tmp_vars(dataset)
dataset |
The input dataset
|
The input dataset with temporary variables removed
get_new_tmp_var()
library(dplyr, warn.conflicts = FALSE)
dm <- tribble(
~DOMAIN, ~STUDYID, ~USUBJID,
"DM", "STUDY X", "01-701-1015",
"DM", "STUDY X", "01-701-1016",
)
dm <- select(dm, USUBJID)
tmp_var <- get_new_tmp_var(dm)
dm <- mutate(dm, !!tmp_var := NA)
## This function creates two new temporary variables which are removed when calling
## `remove_tmp_vars()`. Note that any temporary variable created outside this
## function is **not** removed
do_something <- function(dataset) {
tmp_var_1 <- get_new_tmp_var(dm)
tmp_var_2 <- get_new_tmp_var(dm)
dm %>%
mutate(!!tmp_var_1 := NA, !!tmp_var_2 := NA) %>%
print() %>%
remove_tmp_vars()
}
do_something(dm)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.