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

coerce factor to character in search_names #5

Closed johnbaums closed 9 years ago

johnbaums commented 9 years ago

Just a suggestion - I'm often caught out with taxon names stored as factor, e.g. when I forget to set stringsAsFactors=FALSE when reading in data, or if passing in results of taxize::gbif_parse.

Of course a sensible solution is to remember to set stringsAsFactors=FALSE, and to suggest that gbif_parse returns a character vector for its scientificname element.

However, I wonder if it would be worth coercing factors to character within search_names as well?

raymondben commented 9 years ago

Good suggestion.

(I'm often caught - in R more generally - with factors where I wanted strings. I'm never game to set options(stringsAsFactors=FALSE) globally because I'm sure there's plenty of code that relies on the default TRUE setting for this.)

raymondben commented 9 years ago

Can you give an example please? I'm obviously missing something, because I don't see factors in the output from search_names.

Thanks ...

johnbaums commented 9 years ago

Ah, sorry - I was unclear... I was referring to factor input.

    dat <- read.table(text='species
               Burramys parvus
               Cygnus atratus', sep='\n', header=TRUE)
    search_names(dat$species)
    ## Error: taxa is not a character vector
raymondben commented 9 years ago

Done in v1.12 (in functions search_names, species_info, taxinfo_download, occurrences, and search_fulltext)

> search_names(factor("Burramys parvus"))
  searchTerm        name              commonName                                                                       rank     
1 "Burramys parvus" "Burramys parvus" " Broom's Pygmy-possum,  Burramys, Mountain Pygmy Possum, Mountain Pygmy-possum" "species"
  guid                                                                         
1 "urn:lsid:biodiversity.org.au:afd.taxon:3f17cf84-982a-48f2-9500-e44dcd30710a"