get_cache_or_create {wrappr}R Documentation

Checks if variable exists in environment and returns back or creates a new variable

Description

Checks if variable exists in environment and returns back or creates a new variable

Usage

get_cache_or_create(
  var,
  func,
  ...,
  exists_func_args = NA,
  get_func_args = NA,
  warning_msg = NA_character_
)

Arguments

var

character. The name of the variable to check in the global environment.

func

function. A function that returns a value.

...

Additional arguments to be passed to the param func.

exists_func_args

list. A list of arguments to use in base::exists.

get_func_args

list. A list of arguments to use in bass::get.

warning_msg

character. Message sent to stop function if an error occurs.

Value

Unknown. The return type from the param func or the existing variable in global environment.

Examples

## Not run: 
df <- data.frame(col_1 = c("a","b","c"), col_2 = c(1,2,3))

create_blank_df <- function() {

    data.frame(col_1 = NA_character_, col_2 = NA_integer_)

    }

df_1 <- get_cache_or_create(
                          "df",
                          create_blank_df
                          )

df_2 <- get_cache_or_create(
                          "df_2",
                          create_blank_df
                          )

## End(Not run)

[Package wrappr version 0.1.0 Index]