ropensci / emld

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

Add warning/error when the user sets an invalid EML version string #57

Closed amoeba closed 4 years ago

amoeba commented 4 years ago

Ran into this one today and I'll admit it got me too. To toggle between EML versions, we provide the API:

emld::eml_version("eml-2.1.1")

If you forgot this exact pattern (eml- followed by the version), you might try

emld::eml_version("2.1.1")

which will cause you grief. I think a warning is in order. Maybe an error?

e.g.,

> eml_version("2.1.1")
[1] "2.1.1"
Warning message:
In eml_version("2.1.1") :
  Your provided version of '2.1.1' does not look like a valid version string. Be sure it starts with 'eml-' and ends with the schema version. e.g., for EML 2.1.1, use 'eml-2.1.1'.

Do others think this should be a warning, or maybe think it should be an error instead? Now that I'm asking this, I'm leaning towards error because you get errors in functions like eml_ns when the version string is invalid.

> doc_info <- read_eml(getObject(mn, "foo"))
Error in if (parts[1] <= 2 && parts[2] < 2) { : 
  missing value where TRUE/FALSE needed
cboettig commented 4 years ago

Agreed.

I wonder if it would be a good idea to make this function have an interactive mode as well, so you could call it with no arguments and get an interactive prompt to select a version from a list, rather than assuming the user knows the version.

I'm not sure if that would create a new problem of users forgetting to update the function call when used in non-interactive scripts?

amoeba commented 4 years ago

I like the idea of an interactive-mode menu. For now it could be a choice between 2.1.1 and 2.2.0.

I'm not sure if that would create a new problem of users forgetting to update the function call when used in non-interactive scripts?

Could you explain this a bit more? Ideally, most scripted scenarios shouldn't be mucking with emld::eml_version I hope?