ropensci / datapack

An R package to handle data packages
https://docs.ropensci.org/datapack
44 stars 9 forks source link

Error in rpattrs[["numberReplicas"]] : subscript out of bounds #63

Closed amoeba closed 7 years ago

amoeba commented 7 years ago

I can't reproduce this bug and I could use some help!

While using a package that uses datapack, two of our interns reported this error to me:

Error in rpattrs[["numberReplicas"]] : subscript out of bounds`

They were using a HEAD install of this package (016c9d3544cce03953e1651f184caea4e887f0fb) rather than the published CRAN version and this was because this commit fixed a bug they needed fixed. However, it looks like that fix introduced a bug. I had the interns revert back to the CRAN version and everything started working again.

The line of code producing this error only occurs once in the repo and it looks like it would be caused by the named vector returned by xmlAttrs(xml[["replicationPolicy"]]) not having an element called numberReplicas which should be caused by the replicationPolicy element not having that attribute set.

This is really weird because a valid System Metadata document, if it has a replicationPolicy, must have values set for numberReplicas and replicationAllowed. The object in question causing the issue was on arcticdata.io and the PID is arctic-data.9797.1.

I thought this code would reproduce their error:

library(dataone)
mn <- MNode("https://arcticdata.io/metacat/d1/mn/v2")
getSystemMetadata(mn, "arctic-data.9797.1")

but it doesn't.

I'd like to reproduce the bug before making any code changes but I could at least propose checking that named vector index before accessing it.

Any thoughts?

mbjones commented 7 years ago

I looked into this, and its due to the numberReplicas attribute being missing from the system metadata, and therefor an array out of bounds exception was being thrown. The fix is to test for existence first. The schema doesn't require the numberReplicas attribute, so if it is missing I set the parse routine to set it to 0.