toss: Toss away bad simulated data

Description Usage Examples

View source: R/toss.R

Description

This function returns a function's output if the function runs, or allows the user to customise the error and warning messages if the function throws either.

Usage

1
toss(code, error_msg = NULL, warning_msg = NULL)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
sum(c(1, 2, 3))

# an element of wrong type will cause sum to throw an error
## Not run: 
sum(c(1, 2, "a"))

## End(Not run)

# toss returns function output if function runs
toss(sum(c(1, 2, 3)))

# toss returns NULL by default if function does not run
toss(sum(c(1, 2, "a")))

# toss allows you to customise the error message
toss(sum(c(1, 2, "a")), error_msg = "the cake is a lie")

softloud/metasim documentation built on July 15, 2019, 8:02 p.m.