Skip to contents

Useful when the object depends on a long running task such as a database query.

Usage

create_simple_get_function(obj_nm, env_expr, call_expr, as_character = FALSE)

Arguments

obj_nm

chr Name of the object

env_expr

expr/chr name of the namespace to assign the object to, or an expression that returns the environment to assign to

call_expr

expr The code used to construct the object if the object hasn't already been constructed

as_character

Should the function return code as a character? (Default is an expression)

Value

chr The function at the console for copy/paste

Examples

create_simple_get_function("mt_cars", .GlobalEnv, dplyr::mutate(mtcars, cyl = as.character(cyl)))
#> .Primitive("<-")(get_mt_cars, function (env = .GlobalEnv) 
#> {
#>     if (exists("mt_cars", envir = env)) {
#>         get0("mt_cars", envir = env)
#>     }
#>     else {
#>         dplyr::mutate(mtcars, cyl = as.character(cyl))
#>     }
#> })
#> .Primitive("<-")(get_mt_cars, function (env = .GlobalEnv) 
#> {
#>     if (exists("mt_cars", envir = env)) {
#>         get0("mt_cars", envir = env)
#>     }
#>     else {
#>         dplyr::mutate(mtcars, cyl = as.character(cyl))
#>     }
#> })