remove_tmp_vars {admiraldev}R Documentation

Remove All Temporary Variables Created Within the Current Function Environment

Description

Remove All Temporary Variables Created Within the Current Function Environment

Usage

remove_tmp_vars(dataset)

Arguments

dataset

The input dataset

Value

The input dataset with temporary variables removed

See Also

get_new_tmp_var()

Examples

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)

[Package admiraldev version 1.1.0 Index]