traitecoevo / taxonlookup

A versioned and dynamically updating taxonomic lookup table for land plants
http://onlinelibrary.wiley.com/doi/10.1111/2041-210X.12517/abstract
Other
31 stars 6 forks source link

“subscript out of bounds” on character vector #20

Open rossmounce opened 8 years ago

rossmounce commented 8 years ago

I accidentally input a 'blank' name in a long list of names (an error which I think users are quite likely to make!).

str(A)
 chr [1:337444] "Aa" "Aa" "Aaronsohnia" "Narthecium" "Abarema" ...
lookup_table(A)
Error in FUN(X[[i]], ...) : subscript out of bounds

It would be nice if the lookup_table function could provide a clearer warning about this. Perhaps even print which items in the list are blank OR skip over blank items?

rossmounce commented 8 years ago

I'm aware this is essentially user error, but I do think this is something that is probably likely to be encountered.

Reproducible example:

oneblank <- readLines("https://gist.githubusercontent.com/rossmounce/39858a08494c46471c71/raw/f2270970025e1184063c4b0c9eeebc1cb48401ca/List%2520with%2520a%2520blank",warn=FALSE)
> head(oneblank)
[1] "Aa"          "Aa"          "Aaronsohnia" "Narthecium"  ""            "Abarema"    
> zzz <- lookup_table(oneblank,missing_action="NA",by_species=TRUE)
Error in FUN(X[[i]], ...) : subscript out of bounds
richfitz commented 8 years ago

Thanks Ross. Even if user error, a more informative error message is warranted.