ropensci / emld

:package: JSON-LD representation of EML
https://docs.ropensci.org/emld
Other
13 stars 6 forks source link

Change return type or behavior of as_xml? #69

Closed amoeba closed 3 years ago

amoeba commented 3 years ago

I'm so used to this that I forget that it might be confusing to new users. EML::write_xml returns NULL when you save to disk because of the behavior of emld's as_xml method returns the raw result from xml2::write_xml which returns invisible(). One of our team caught this over on https://github.com/NCEAS/datateam-training/issues/229.

The relevant code is:

## Serialize to file if desired
if(!is.null(file)){
  xml2::write_xml(xml, file)
} else {
  xml
}

I wasn't sure what the best return type is here. The readr functions, which are common to most users, seem to return the input (to support piping). This method currently returns either an xml_document or NULL. Maybe the best thing is just to wrap the write_xml in invisible() and avoid making any big changes to the return type.

Thoughts @cboettig?

amoeba commented 3 years ago

Oh, you know I just saw this in the docstring:

a xml_document object. Or if a file path is provided, the metadata is written out in XML file and the function returns NULL invisibly.

We're not currently doing this so I'll send in a PR.