Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught errors when important fields are missing (using drop) #124

Closed
Lobz opened this issue Jan 21, 2025 · 1 comment
Closed

Uncaught errors when important fields are missing (using drop) #124

Lobz opened this issue Jan 21, 2025 · 1 comment

Comments

@Lobz
Copy link

Lobz commented Jan 21, 2025

I created a small test script for the workflow, which can be used to test:

library(plantR) # used foi reading and cleaning occurrence data
occs_gbif <- rgbif2(species = "Rosaceae",
    country = "BR",
    n.records = 10)
occs <- formatDwc(gbif_data = occs_gbif, drop.empty = TRUE)
occs
occs <- formatOcc(occs)
occs <- formatLoc(occs)
occs <- formatCoord(occs)
occs <- formatTax(occs)

When using small sample datasets like this, it's not unusual that some essential fields will be empty. The problem is that the format functions do not detect this, and instead of failing gracefully they crash with uncaught errors. In this case, the errors are as follows:

> occs <- formatOcc(occs)
Error in `$<-.data.frame`(`*tmp*`, "recordNumber.new", value = character(0)) : 
  replacement has 0 rows, data has 10
> occs <- formatLoc(occs)
Error in `[.data.frame`(x, , match(loc.levels, colnames(x)), drop = FALSE) : 
  undefined columns selected
> occs <- formatCoord(occs)
Error in getCoord(x = coords1, lat.orig, lon.orig, lat.gazet, lon.gazet,  : 
  One or more column names were not found: please check or specify column names
> occs <- formatTax(occs)
> 
LimaRAF added a commit that referenced this issue Jan 26, 2025
…d fields (issue #124), vignette format (issue #121) and some text updates
@LimaRAF
Copy link
Owner

LimaRAF commented Jan 26, 2025

Thanks for this issue. I have not used the package for running such small datasets. But you it should deal with smaller ones with missing fields. I added some patches along formatLoc() to make sure it does not fail any more. Not sure now if any other function may need the same patches. But at least I could not reproduce the error using your small test script after the changes I did in commit ac17995. Please let me know if you find any other issue related to this in other functions.

@LimaRAF LimaRAF closed this as completed Jan 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants