Skip to content

Commit

Permalink
improve detection of non-lists
Browse files Browse the repository at this point in the history
  • Loading branch information
equitable-equations committed Dec 30, 2023
1 parent fcc027a commit 277d58a
Showing 1 changed file with 12 additions and 31 deletions.
43 changes: 12 additions & 31 deletions R/is_inventory_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,29 @@
#'
#' @noRd

is_inventory_list <- function(possible_inventory) {


is_inventory_list <- function(possible_list) {
return <- TRUE

if (is.null(possible_list)) {
return <- FALSE
}
return <- FALSE

tryCatch({
if (!is.list(possible_list)) {
return <- FALSE
}

if (length(possible_list) == 0) {
return <- FALSE
}

if (!is.data.frame(possible_list[[1]])) {
return <- FALSE
}

if (ncol(possible_list[[1]]) != 9) {
return <- FALSE
}

if (colnames(possible_list[[1]])[1] != "scientific_name" |
colnames(possible_list[[1]])[2] != "family" |
colnames(possible_list[[1]])[3] != "acronym" |
colnames(possible_list[[1]])[4] != "nativity" |
colnames(possible_list[[1]])[5] != "c" |
colnames(possible_list[[1]])[6] != "w" |
colnames(possible_list[[1]])[7] != "physiognomy" |
colnames(possible_list[[1]])[8] != "duration" |
colnames(possible_list[[1]])[9] != "common_name") {
if (is.list(possible_inventory) & (length(possible_inventory) != 0)) {
outcomes <- lapply(possible_inventory,
is_inventory) |>
as.logical()
return <- all(outcomes)
} else {
return <- FALSE
}

},
error = function(e) {
return <- FALSE
},
warning = function(w){
return <- FALSE
})

return

}

0 comments on commit 277d58a

Please sign in to comment.