Allows for errors to be easily analyzed.

get_errors_one_var(pmap_safely_output, var, specific = FALSE)

get_errors(pmap_safely_output, specific = FALSE)

Arguments

pmap_safely_output

The data frame outputted by the function pmap_safely_output. More specifically, must have an error and a result column (which is a list containing named lists or vectors).

var

The input variable to analyzed errors based on.

specific

Do you just want a summary or specific errors?

Examples

# a function to apply calculate_if_positive <- function(a, b){ if(a < 0 & b < 0) {stop("Both numbers are negative.")} else if(a < 0) {stop("Just the first number is negative")} else if(b < 0) {stop("Just the second number is negative")} list(add = a + b, subtract = a - b, multiply = a * b, divide = a / b) } # data frame to apply the function to by row numbers <- data.frame(a = c(-1, 0, 1, 2), b = c(2, 1, 0, -1), irrelevant = c("minneapolis", "st_paul", "minneapolis", "st_paul")) # apply and get errors output <- pmap_safely(numbers, calculate_if_positive)
#> Note that the function does not use the following variables: irrelevant
get_errors_one_var(output, var = "a")
#> # A tibble: 4 x 5 #> variable value n_errors count error_rate #> <chr> <chr> <int> <int> <dbl> #> 1 a -1 1 1 1 #> 2 a 2 1 1 1 #> 3 a 0 0 1 0 #> 4 a 1 0 1 0
get_errors_one_var(output, var = "a", specific = TRUE)
#> # A tibble: 4 x 6 #> variable value error n count rate #> <chr> <chr> <chr> <int> <int> <dbl> #> 1 a -1 Just the first number is negative 1 1 1 #> 2 a 0 <NA> 1 1 1 #> 3 a 1 <NA> 1 1 1 #> 4 a 2 Just the second number is negative 1 1 1
get_errors(output)
#> # A tibble: 10 x 5 #> variable value n_errors count error_rate #> <chr> <chr> <int> <int> <dbl> #> 1 a -1 1 1 1 #> 2 a 2 1 1 1 #> 3 a 0 0 1 0 #> 4 a 1 0 1 0 #> 5 b -1 1 1 1 #> 6 b 2 1 1 1 #> 7 b 0 0 1 0 #> 8 b 1 0 1 0 #> 9 irrelevant minneapolis 1 2 0.5 #> 10 irrelevant st_paul 1 2 0.5
get_errors(output, specific = TRUE)
#> # A tibble: 12 x 6 #> variable value error n count rate #> <chr> <chr> <chr> <int> <int> <dbl> #> 1 a -1 Just the first number is negative 1 1 1 #> 2 a 0 <NA> 1 1 1 #> 3 a 1 <NA> 1 1 1 #> 4 a 2 Just the second number is negative 1 1 1 #> 5 b -1 Just the second number is negative 1 1 1 #> 6 b 0 <NA> 1 1 1 #> 7 b 1 <NA> 1 1 1 #> 8 b 2 Just the first number is negative 1 1 1 #> 9 irrelevant minneapolis <NA> 1 2 0.5 #> 10 irrelevant minneapolis Just the first number is negative 1 2 0.5 #> 11 irrelevant st_paul <NA> 1 2 0.5 #> 12 irrelevant st_paul Just the second number is negative 1 2 0.5