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

eml_validate with EML containing an unitList #207

Closed maelle closed 7 years ago

maelle commented 7 years ago

Is there a test of EML validation when the EML has an unitList? I couldn't find one.

I had an EML that used to get TRUE from eml_validate. I created it this way:

units <- read_csv2("eml/units.csv")
 units <- set_unitList(units, as_metadata = TRUE)
eml <- new("eml",
           packageId = "27d5efb0-36da-11e6-9b72-739b6f659122",  # from uuid::UUIDgenerate(),
           system = "uuid", 
           dataset = dataset,
           additionalMetadata = units)
write_eml(eml, "ambient_DB_eml.xml")

eml_validate("ambient_DB_eml.xml", encoding = "latin1")
#> [1] FALSE
#> attr(,"errors")
#> [1] "Element 'unitList': This element is not expected. Expected is one of ( describes, metadata )."
 class(units)
#> [1] "additionalMetadata"
#> attr(,"package")
#> [1] "EML"

I've also tried to do something closer to the units vignette (but well it's really the same?)

units <- read_csv2("eml/units.csv")
units <- set_unitList(units)
eml <- new("eml",
           packageId = "27d5efb0-36da-11e6-9b72-739b6f659122",  # from uuid::UUIDgenerate(),
           system = "uuid", 
           dataset = dataset,
           additionalMetadata = as(units, "additionalMetadata"))

write_eml(eml, "ambient_DB_eml.xml")

eml_validate("ambient_DB_eml.xml", encoding = "latin1")
#> [1] FALSE
#> attr(,"errors")
#> [1] "Element 'unitList': This element is not expected. Expected is one of ( describes, metadata )."

cc @carlesmila

cboettig commented 7 years ago

Good question, I'll have to dig into the error. But yes, there's https://github.com/ropensci/EML/blob/master/inst/xsd/test/eml-datasetWithUnits.xml

all those test files that start with eml- are tested for basic roundtrip read/write/validate by https://github.com/ropensci/EML/blob/master/tests/testthat/test-testfiles.R, so that should at least give you a starting point.

I'd bet the problem here is probably the coercion for as(..., additionalMetadata) needs to be updated for xml2....

maelle commented 7 years ago

Ok I'll have a look next week (working day almost over here :wink: )

maelle commented 7 years ago

In the example file the unitList starts by:

  <additionalMetadata>
    <metadata>
      <stmml:unitList

In my file it starts by:

<additionalMetadata>
    <unitList 
maelle commented 7 years ago

I'll try to think of an easy example with unitList that'd be created from scratch in the tests, I guess it'd be useful (my own EML is huge).

maelle commented 7 years ago

Note, because I also suspect the problem is the coercion, and because I am not able to understand how to fix this, I'll stop investigating for now. :angel:

maelle commented 7 years ago

Test added (well I hope it'd be a valid one if not for the current bug... just replaced meters with terameters in the example EML from the creating EML vignette, and added a very small units data.frame with only id and unitType)

maelle commented 7 years ago

@cboettig you've now removed the test with an unit list? If so why?

maelle commented 7 years ago

Oops sorry I found it again @cboettig

maelle commented 7 years ago

So you solved this in https://github.com/ropensci/EML/commit/be0faa72d4eefa3a489fefc0860aa8df22d28aea

and I can validate my own EML, thanks a lot!! Well I guess you knew you had fixed it when the test started passing. :grin: