Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change default schemaLocation so it points at a URL #45

Merged
merged 2 commits into from Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions R/as_xml.R
Expand Up @@ -25,21 +25,21 @@
#' @return 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.
as_xml <- function(x, file=NULL, root = "eml", ns = "eml",
schemaLocation = paste0(eml_ns(), "/ eml.xsd"))
schemaLocation = eml_schema_location())
{
UseMethod("as_xml")
}

#' @export
as_xml.list <- function(x, file=NULL, root = "eml", ns = "eml",
schemaLocation = paste0(eml_ns(), "/ eml.xsd")){
schemaLocation = eml_schema_location()){
x <- as_emld.list(x)
as_xml.emld(x, file)
}

#' @export
as_xml.emld <- function(x, file=NULL, root = "eml", ns = "eml",
schemaLocation = paste0(eml_ns(), "/ eml.xsd")){
schemaLocation = eml_schema_location()){
## Frame/compact into original context for a standardized structure
x <- eml_frame(x)

Expand Down
33 changes: 33 additions & 0 deletions R/eml_version.R
Expand Up @@ -46,3 +46,36 @@ eml_ns <- function(version = eml_version()) {

paste0(prefix, version)
}

# Helper string used below to factor out the host from the generation of
# schemaLocation values
eml_host <- "https://eml.ecoinformatics.org"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, unless we feel it should be configurable as an option. But why make it a package global variable? It seems more natural to me to make eml_host an optional argument to the new eml_schema_location() function, with this as the default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a better approach.


#' Get an appropriate `schemaLocation` value for a given version of the schema
#'
#' This is a simple helper to make filling in the `schemaLocation` attribute
#' on documents this package creates.
#'
#' @param version Optional. Override the version of the schema.
#' @param url Override the URL portion of the `schemaLocation` value.
#'
#' @return Returns a string suitable as a value for `schemaLocation`.
#' @examples
#' \dontrun{
#' # Get an appropriate schemaLocation value for the current version fo EML
#' eml_schema_location()
#'
#' # Get an appropriate value for EML 2.1.1
#' eml_schema_location("eml-2.1.1")
#'
#' # Set `schemaLocation` to a custom URL of your choosing
#' eml_schema_location(url = "https://example.org/eml.xsd")
#' }
eml_schema_location <- function(version = eml_version(), url = NULL) {
# Fill in a default value if `url` is not set
if (is.null(url)) {
url <- paste(eml_host, version, "eml.xsd", sep = "/")
}

paste(eml_ns(version), url)
}
9 changes: 7 additions & 2 deletions man/as_xml.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions man/eml_schema_location.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.