ropensci / rfishbase

R interface to the fishbase.org database
https://docs.ropensci.org/rfishbase
109 stars 40 forks source link

common_to_sci for other languages #275

Open epistecius opened 6 months ago

epistecius commented 6 months ago

Hi,

can't seem to get the command common_to_sci to work for other languages.

common_to_sci( "Plötze", Language = "German" )

common_to_sci( "Blankvoorn", Language = "Dutch" )

common_to_sci( "Gardon", Language = "French" )

all deliver zero results.

And, common_to_sci( "Roach", Language = "German" )

Delivers all roaches in the english db, irrepsective of the language indicated.

I'm using rFishbase Version 4.1.2. on R version 4.2.2 (2022-10-31 ucrt), platform x86_64-w64-mingw32

Thanks, David

fishheadmaggus commented 6 months ago

There are two bugs in common_to_sci(): (1) "Language" is not forwarded to get_comnames(), (2) the function name in line 7 must be enquote() instead of enquo(). This here seems to work from the R command line:

common_to_sci <- function(x, Language = "English", server = getOption("FISHBASE_API", "fishbase"), 
                          version = rfishbase:::get_latest_release(), db = rfishbase:::default_db()) 
{
  comnames <- rfishbase:::get_comnames(lang = Language, server, version, db) %>% dplyr::collect()
  subset <- purrr::map_dfr(x, function(y) {
    y <- stringr::str_to_lower(y)
    y <- enquote(y)
    dplyr::filter(comnames, grepl(!!y, stringr::str_to_lower(ComName)))
  })
  subset
}