Skip to content

Instantly share code, notes, and snippets.

@sharlagelfand
Created February 18, 2020 17:55
Show Gist options
  • Save sharlagelfand/be7661e22214db8bb5caa82a204fa59a to your computer and use it in GitHub Desktop.
Save sharlagelfand/be7661e22214db8bb5caa82a204fa59a to your computer and use it in GitHub Desktop.
divide_by_two <- function(x, call. = FALSE) {
if(!is.numeric(x)) {
stop("IT'S NOT NUMERIC", call. = call.)
} else {
x/2
}
}
divide_by_two(2)
#> [1] 1
divide_by_two("dog")
#> Error: IT'S NOT NUMERIC
divide_by_two("dog", call. = TRUE)
#> Error in divide_by_two("dog", call. = TRUE): IT'S NOT NUMERIC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment