set_up {dreamerr}R Documentation

Sets "semi-globally" the 'up' argument of dreamerr's functions

Description

When check_arg (or stop_up) is used in non user-level functions, the argument .up is used to provide an appropriate error message referencing the right function.

Usage

set_up(.up = 1)

Arguments

.up

An integer greater or equal to 0.

Details

To avoid repeating the argument .up in each check_arg call, you can set it (kind of) "globally" with set_up.

The function set_up does not set the argument up globally, but only for all calls to check_arg and check_value within the same function.

Examples


# Example with computation being made within a non user-level function

sum_fun = function(x, y){
  my_internal(x, y, sum = TRUE)
}

diff_fun = function(x, y){
  my_internal(x, y, sum = FALSE)
}

my_internal = function(x, y, sum){
  set_up(1) # => errors will be at the user-level function
  check_arg(x, y, "numeric scalar mbt")

  # Identical to calling
  # check_arg(x, y, "numeric scalar mbt", .up = 1)

  if(sum) return(x + y)
  return(x - y)
}

# we check it works
sum_fun(5, 6)
diff_fun(5, 6)

# Let's throw some errors
try(sum_fun(5))
try(sum_fun(5, 1:5))


[Package dreamerr version 1.4.0 Index]