ropensci / EML

Ecological Metadata Language interface for R: synthesis and integration of heterogenous data
https://docs.ropensci.org/EML
Other
98 stars 33 forks source link

`get_attributes` fails if there is only one attribute #285

Open jeanetteclark opened 4 years ago

jeanetteclark commented 4 years ago

Pretty sure this is because of the unboxing issue. I'll try to put in a fix for this when I can, but if anyone else wants to have at it, here is a reprex



me <- list(individualName = list(givenName = "Jeanette", surName = "Clark"))

attributes <- data.frame(attributeName = 'length_1',
                         attributeDefinition = 'def1',
                         measurementScale = 'ratio',
                         domain = 'numericDomain',
                         unit = 'meter',
                         numberType = 'real',
                         stringsAsFactors = FALSE)

att_list <- set_attributes(attributes)

doc_ex <- list(packageId = "id", system = "system", 
            dataset = list(title = "A Mimimal Valid EML Dataset",
                           creator = me,
                           contact = me,
                           dataTable = list(entityName = "data table", attributeList = att_list))
)

get_attributes(doc_ex$dataset$dataTable)
#> Error in if (measurementScale == "dateTime" & is.null(domain)) {: argument is of length zero```
jeanetteclark commented 4 years ago

I realized today that this is an error on my part - get_attributes needs to be run on an attributeList not the entity.

cboettig commented 4 years ago

hmm, I wonder if we could a some type-checking step to get_attributes() so that it throws a more helpful error message at least...

ianbrunjes commented 3 years ago

Reopening, as this unboxing issue does seem to occur, provided that the eml is read from a file and not simply generated in code. Modifying @jeanetteclark's MRE to write and then read the simple EML before calling get_attributes yields an error when only one attribute is present.

me <- list(individualName = list(givenName = "Brunjes", surName = "Ian"))
attributes <- data.frame(attributeName = 'length_1',
                         attributeDefinition = 'def1',
                         measurementScale = 'ratio',
                         domain = 'numericDomain',
                         unit = 'meter',
                         numberType = 'real',
                         stringsAsFactors = FALSE)
att_list <- set_attributes(attributes)
doc_ex <- list(packageId = "id", system = "system", 
            dataset = list(title = "A Mimimal Valid EML Dataset",
                           creator = me,
                           contact = me,
                           dataTable = list(entityName = "data table", attributeList = att_list))
)
write_eml(doc_ex, "tempfile.xml")
eml_from_file <- read_eml("tempfile.xml")
file.remove("tempfile.xml")
get_attributes(eml_from_file$dataset$dataTable$attributeList)
# Error: $ operator is invalid for atomic vectors