discard_errors: Discards elements of list that have an error value from...

View source: R/discard_errors.R

discard_errorsR Documentation

Discards elements of list that have an error value from purrr::safely.

Description

Used in scrapping, when swim_parse is applied over a list of results using purrr::map the result is a list of two element lists. The first element is the results, the second element is an error register. This function removes all elements where the error register is not NULL, and then returns the results (first element) of the remaining lists.

Usage

discard_errors(x)

Arguments

x

a list of lists from purrr::map and purrr:safely

Value

a list of lists where sub lists containing a non-NULL error have been discarded and error elements have been removed from all remaining sub lists

Examples

result_1 <- data.frame(result = c(1, 2, 3))
error <- NULL

list_1 <- list(result_1, error)
names(list_1) <- c("result", "error")

result_2 <- data.frame(result = c(4, 5, 6))
error <- "result is corrupt"

list_2 <- list(result_2, error)
names(list_2) <- c("result", "error")

list_of_lists <- list(list_1, list_2)
discard_errors(list_of_lists)


gpilgrim2670/SwimmeR documentation built on March 26, 2023, 5:05 p.m.