AtlasOfLivingAustralia / ALA4R

Access data and resources hosted by the Atlas of Living Australia (ALA)
https://atlasoflivingaustralia.github.io/ALA4R/
42 stars 8 forks source link

search_names inconsistency #6

Closed johnbaums closed 9 years ago

johnbaums commented 9 years ago

If an unrecognised taxon name is passed to search_names, it returns

<0 x 0 matrix>

But if a vector of unrecognised names (i.e. none of them are recognised) is passed, it returns

Error in if (!empty(x)) { : missing value where TRUE/FALSE needed

e.g.

search_names('Foo')
# <0 x 0 matrix>

and

search_names(c('Foo', 'Bar', 'Baz'))
#   searchTerm name                                              rank      guid                                            
#1 "Foo"      NA                                                NA        NA                                              
#2 "Bar"      "Acacia sp. Marble Bar (J.G. & M.H.Simmons 3499)" "species" "urn:lsid:biodiversity.org.au:apni.taxon:710866"
#3 "Baz"      NA                                                NA        NA                     

but

search_names(c('Foo', 'Baz'))
# Error in if (!empty(x)) { : missing value where TRUE/FALSE needed
raymondben commented 9 years ago

Grrrr! Well spotted! (Partially) fixed in 1.13 (see below) - the result for multiple unmatched names is now an empty data frame (the same as it is for a single unmatched name). But I think it would be more consistent for this to be a data frame with at least the column names "searchTerm","name","commonName","rank","guid" (i.e. the core set that is present in the result for a matched name).

> search_names("fljkhdlsi")
<0 x 0 matrix>

> search_names(c("fljkhdlsi","lfajldlo"))
<0 x 0 matrix>

> search_names(c("Grevillea"))
  searchTerm  name        commonName                 rank    guid                                            
1 "Grevillea" "Grevillea" "Grevillea, Spider Flower" "genus" "urn:lsid:biodiversity.org.au:apni.taxon:378603"

> search_names(c("Grevillea","k.jkasdfou"))
  searchTerm   name        commonName                 rank    guid                                            
1 "Grevillea"  "Grevillea" "Grevillea, Spider Flower" "genus" "urn:lsid:biodiversity.org.au:apni.taxon:378603"
2 "k.jkasdfou" NA          NA                         NA      NA                                              

> search_names(c("Grevillea","Macropus","fksdjhfui"))
  searchTerm  name        commonName                 rank    guid                                                                         
1 "Grevillea" "Grevillea" "Grevillea, Spider Flower" "genus" "urn:lsid:biodiversity.org.au:apni.taxon:378603"                             
2 "Macropus"  "Macropus"  NA                         "genus" "urn:lsid:biodiversity.org.au:afd.taxon:9e6a0bba-de5b-4465-8544-aa8fe3943fab"
3 "fksdjhfui" NA          NA                         NA      NA                                                                           
johnbaums commented 9 years ago

Great - thanks. I agree, returning a data.frame with searchTerm filled and other columns NA (as per row 3 of your last example above) would be sensible.

raymondben commented 9 years ago

PS The

<0 x 0 matrix>

output comes from the print function for that class, which coerces to a matrix before printing. But I think that's unhelpfully misleading ...

raymondben commented 9 years ago

Fixed in v1.14. All-unmatched names should now return an NA-populated data.frame or list (when guids_only=TRUE) rather than an empty one. Print method also tweaked slightly.