ropensci / rfishbase

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

Error with SeaLifeBase Query #83

Closed amroco closed 8 years ago

amroco commented 8 years ago

Hi,

Getting the following error when querying SLB for SpecCodes for a list of species, (but no dramas when using the same list of species in the validate_names function).

Error in vapply(elements, encode, character(1)) : values must be length 1, but FUN(X[[1]]) result is length 2

Thanks

sckott commented 8 years ago

Thanks for the report @amroco will have a look

sckott commented 8 years ago

@amroco Please do share what your query was

and what version of rfishbase/R/operating system are you using

amroco commented 8 years ago

Sweet, thanks bud,

So this works fine:

New_Taxon_invert_spp_val=validate_names(New_Taxon_invert_spp) str(New_Taxon_invert_spp_val) New_Taxon_invert_spp_val=as.character(New_Taxon_invert_spp_val)

304 obs now, so a difference of 63 obs

Difference=New_Taxon_invert_spp[!(New_Taxon_invert_spp %in% New_Taxon_invert_spp_val)] str(Difference) Difference

There are 82 differences in names, check how many have no TaxonKey later

This doesn't work:

New_Taxon_for_upload_just_inverts_addinfo <- species(New_Taxon_invert_spp_val, fields=c("SpecCode"))

head(New_Taxon_for_upload_just_inverts_addinfo) Thanks so much, Amy

sckott commented 8 years ago

can you paste in the contents of New_Taxon_invert_spp or email it to me (scott@ropensci.org)

or at least part of its contents, including some causing a problem

sckott commented 8 years ago

@cboettig hmm, looking into this and getting the same error as above, looks like may come down to the internal taxa() function that is matching names against a cached version of a species table. Is this species table only for fishbase, or for both fishbase and sealifebase?

amroco commented 8 years ago

Will email it :) I had a similar problem with GenCodes for FB, but worked that out- however my solution isn't fixing this issue (partially because I don't know what I did to fix that problem in the first place). Cheers, A

sckott commented 8 years ago

thanks

been making some small changes to the API, so maybe something broken on that end

sckott commented 8 years ago

@amroco try it again after re-installing from a different branch: devtools::install_github("ropensci/rfishbase@sckott-endpoint-fix")

sckott commented 8 years ago

@cboettig I made a change on branch sckott-endpoint-fix - the changes I made https://github.com/ropensci/rfishbase/compare/master...sckott-endpoint-fix were just to get a unique set of results when calling speccodes() and when calling species_names() as in some cases those were resulting in more than one result, some of which were the same names - Anything seem off about that. All tests and checks are fine

cboettig commented 8 years ago

good catch, thanks. PR?

sckott commented 8 years ago

yeah

sckott commented 8 years ago

@amroco

Reinstall from master just so that we're o the same page devtools::install_github("ropensci/rfishbase")

Then here's the code I have, some var names changed to be a bit shorter

library(rfishbase)
options(FISHBASE_API = "http://fishbase.ropensci.org/sealifebase")
xx <- read.csv("~/Downloads/New_Taxon_invert_spp.csv", stringsAsFactors = FALSE)[,2]
length(xx)
xx_val <- validate_names(xx)
length(xx_val)
xx_val <- as.character(xx_val)
# however, on this next line I get that error you get
# which looks like it drills down to be a http request error, but i haven't been 
# able to track it down yet
(x_addinfo <- species(xx_val, fields="SpecCode")) 

although, when I do

res <- list()
for (i in seq_along(xx_val)) {
  cat(i, sep = "\n")
  res[[i]] <- species(xx_val[i], fields="SpecCode")
}

it works fine, so seems maybe there's something going on with the http requests, maybe too many requests back to back - Still trying to track this down...

amroco commented 8 years ago

Thanks Scott, Currently:

res <- list() for (i in seq_along(New_Taxon_inverts_val)) { cat(i, sep = "\n") res[[i]] <- species(New_Taxon_inverts_val[i], fields="SpecCode") }

just produces a list of sequential numbers from 1 to 304 for me, so no luck there at the moment.

sckott commented 8 years ago

The output is in the res object :)

sckott commented 8 years ago

you can combine like dplyr::bind_rows(res)

amroco commented 8 years ago

yikes! that;s a glaring rookie mistake, thanks for your help :)

sckott commented 8 years ago

i think i figured out the problem, fix coming

sckott commented 8 years ago

@amroco try reinstalling like devtools::install_github("ropensci/rfishbase@sckott-make-unique")

that should work now, there were some names giving back duplicate codes for some reason, and then the internal parsing borked on that.

sckott commented 8 years ago

did that work for you @amroco

sckott commented 8 years ago

@amroco merged those changes into master, now just do devtools::install_github("ropensci/rfishbase") the other branch is now deleted