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

[formatOccs] Error in gsub(x, "", y, fixed = TRUE) : zero-length pattern #125

Open
Lobz opened this issue Jan 21, 2025 · 2 comments
Open

Comments

@Lobz
Copy link

Lobz commented Jan 21, 2025

I have no idea why this is happening, please help. This is the dataset I'm using: https://api.gbif.org/v1/occurrence/download/request/0061636-241126133413365.zip

Here's my code:

# read data from file
gbif_raw <- readData("../../BIOTA/GBIF/0061636-241126133413365.zip", quote = "", na.strings = c("", "NA"))
gbif_raw <- gbif_raw[[1]]

occs <- formatDwc(gbif_data = gbif_raw)
occs <- formatOcc(occs)

And here's the error I'm getting:

Error in gsub(x, "", y, fixed = TRUE) : zero-length pattern
@Lobz
Copy link
Author

Lobz commented Jan 23, 2025

Determined the problem is actually here:

occs$recordedBy.new <- fixName(occs$recordedBy)
occs$recordedBy.aux <- prepName(occs$recordedBy.new,
                            fix.names = FALSE,
                            sep.out = "; ",
                            output = "aux")

@Lobz
Copy link
Author

Lobz commented Jan 23, 2025

The error occurs in line 14 of lastName.R, when the input has a name starting with a comma. In my input I found the following:

> x[(grepl("^,",x))]
[1] ", J.P. Souza, V.R. Scalon, G.O. Romao, M.I.R.G. Oliveira, A.L.F. Dutra"

I thought the name might have been split incorrectly but actually the input really does start with a comma AFTER a ; separating the first author

> gbif_raw$recordedBy[grepl(found, x)]
[1] "Souza, V.C.; , J.P.Souza, V.R.Scalon, G.O.Romão, M.I.R.G.Oliveira, A.L.F.Dutra"

My suggestions are: add a safeguard (maybe a try) to skip errors, and remove any commas at the start of strings.

Lobz added a commit to Lobz/plantR that referenced this issue Jan 23, 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

1 participant