DataONEorg / rdataone

R package for reading and writing data at DataONE data repositories
http://doi.org/10.5063/F1M61H5X
36 stars 19 forks source link

DataTable attributes cause error with EML::get_attributes() function when only 1 attribute is documented #303

Open justinkadi opened 4 months ago

justinkadi commented 4 months ago

Steps to Reproduce

Set up node and gather data package

d1c <- dataone::D1Client("STAGING", "urn:node:mnTestARCTIC") # Setting the Member Node resourceMapId <- "resource_map_urn:uuid:4598abc4-c02e-4d38-a16e-92141cf2ec74" # Get data package PID (resource map ID) dp <- dataone::getDataPackage(d1c, identifier = resourceMapId, lazyLoad = TRUE, quiet = FALSE) # Gather data package

Load in Metadata EML

metadataId <- datapack::selectMember(dp, name="sysmeta@formatId", value="https://eml.ecoinformatics.org/eml-2.2.0") # Get metadata PID doc <- EML::read_eml(getObject(d1c@mn, metadataId)) # Read in metadata EML file

attList <- EML::get_attributes(doc$dataset$dataTable[[2]]$attributeList)

## Observed Outcome
- I get an error when trying to get the attribute list from the 2nd file `Error in x$measurementScale : $ operator is invalid for atomic vectors` using the `EML::get_attributes()` function
- The error happens on [this line](https://github.com/ropensci/EML/blob/HEAD/R/get_attributes.R#L56) in the `get_attributes()` function within the EML package

## Expected Outcome
- The function should have grabbed the attribute list. It works with the first file that has 2 attributes, but not when it is just 1 attribute.

attList <- EML::get_attributes(doc$dataset$dataTable[[2]]$attributeList)


## Additional Notes
- It looks like this is because when there are multiple attributes in an attributeList, each attribute is listed, but when there's only 1 attribute, it is not nested under its own list. 
<img width="737" alt="Screen Shot 2024-04-19 at 3 37 10 PM" src="https://github.com/NCEAS/metacat/assets/39847639/3426a36b-94b9-4ffb-bf49-4135b51f4d7e">

- This happens in production as well, so it isn't a new issue with Metacat 3.0
- This could either be fixed in the EML package to be more flexible, or in the way the EML docs are created from the web form