ropensci / neotoma

Programmatic R interface to the Neotoma Paleoecological Database.
https://docs.ropensci.org/neotoma
Other
30 stars 16 forks source link

Strange error from `get_chroncontrol` invalid `chronology.id`. #183

Closed SimonGoring closed 9 years ago

SimonGoring commented 9 years ago

A user has reported that the following code:

nh11k.datasets <- get_dataset(datasettype='pollen', ageold = 12000,ageyoung=-100)
nh11k.sites <- get_site(nh11k.datasets)
new.downs <- get_download(nh11k.datasets) #this gives me a list that is 124 Mb with all sites and data
new.downs2=get_chroncontrol(new.downs)

returns the following message:

#> API call was successful. Returned chronology
#> "Error in get_chroncontrol.default(y$sample.meta$chronology.id[1], verbose) : chronology ID (x) must be numeric."

I'm not sure if this is an error with a poorly assigned chronology.id (or empty value) passed by Neotoma itself or an error in the function. I'm running some tests to see. If it's the site I'll add a try-catch and put something in the tests.

SimonGoring commented 9 years ago

So it's clearly an error in the assignment of chronology.ids. Changing the code to:

new.downs2<-lapply(new.downs, function(x)try(get_chroncontrol(x)))
which(sapply(new.downs2, class) == 'try-error')

returns:

#>  1776  3051  3483  3869  3973  4196  4197 14839 15628 
#>  579   942   977  1039  1093  1228  1229  1624  1800 

Of these, 5 have NA values for the chronology.id. It's a bit strange:

Of the remaining records (dataset IDs 1376, 1430, 7878 and 8294), we get the error:

#> Error in do.call(rbind.data.frame, lapply(aa, "[[", "controls")[[1]]) : 
#>  second argument must be a list 

It looks like the problem arises from the fact that all of these only have a single object in their chroncontrol table, causing control.table <- do.call(rbind.data.frame, lapply(aa, '[[', 'controls')[[1]]) to fail.

This is fairly easy to fix (in general).

SimonGoring commented 9 years ago

This seems to have been resolved in v1.3.0, the errors must have been from the use of an older version. I'm going to close this issue.

SimonGoring commented 9 years ago

I was wrong. This is a different error than the one I fixed. This one is caused by NA values in the chronology table.

SimonGoring commented 9 years ago

This error now seems to be resolved following commit https://github.com/ropensci/neotoma/commit/b13cf352b6f042792ad44b464605288cb88d98c3 which now does the check for NA values in the chronology.id before it gets passed to the API.