Skip to content

Commit d08d3e0

Browse files
Merge pull request #196 from NCEAS/develop
add eml_add_distrubution function
2 parents 729f99a + 5ccf971 commit d08d3e0

File tree

5 files changed

+102
-1
lines changed

5 files changed

+102
-1
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ Suggests:
5555
testthat,
5656
xslt,
5757
yaml
58-
RoxygenNote: 7.1.1
58+
RoxygenNote: 7.1.2
5959
Roxygen: list(markdown = TRUE)
6060
VignetteBuilder: knitr

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export(create_dummy_package_full)
1010
export(create_dummy_parent_package)
1111
export(create_resource_map)
1212
export(eml_adcad_annotation)
13+
export(eml_add_distribution)
1314
export(eml_add_entity_system)
1415
export(eml_add_publisher)
1516
export(eml_associated_party)

R/eml.R

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,3 +683,52 @@ eml_categorize_dataset <- function(doc, discipline){
683683

684684
return(doc)
685685
}
686+
687+
688+
#' Add distribution information to EML
689+
#'
690+
#' Adds a landing page URL to the dataset, and corrects the metadata identifier
691+
#' by replacing the existing identifier with that which is passed. Note that this
692+
#' function constructs landing page URLs for the Arctic Data Center only and will not work
693+
#' correctly on other repositories.
694+
#'
695+
#'
696+
#'
697+
#' @param doc (emld) An EML document
698+
#' @param identifier (character) A pre-issued, unassigned identifier (as from `dataone::generateIdentifier()`)
699+
#'
700+
#' @return doc (emld) An EML document with distribution added
701+
#' @export
702+
#' @examples
703+
#' \dontrun{
704+
#' library(EML)
705+
#' d1c <- dataone::D1Client("STAGING", "mnTestARCTIC")
706+
#' # read in any EML document
707+
#' doc <- read_eml(system.file("extdata/strix-pacific-northwest.xml", package="dataone"))
708+
#' # generate a doi
709+
#' id <- generateIdentifier(d1c@mn, "doi")
710+
#' doc <- eml_add_distribution(doc, id)
711+
#' }
712+
#'
713+
eml_add_distribution <- function(doc, identifier){
714+
715+
stopifnot("emld" %in% class(doc))
716+
717+
doc$packageId <- identifier
718+
719+
use_doi <- grepl("doi", identifier)
720+
721+
# Add landing page
722+
if (use_doi == T){
723+
doc$dataset$distribution$offline <- NULL
724+
doc$dataset$distribution$online$url <- list(url = paste0("http://doi.org/", identifier),
725+
`function` = "information")
726+
}
727+
else if (use_doi == F){
728+
doc$dataset$distribution$offline <- NULL
729+
doc$dataset$distribution$online$url <- list(url = paste0("http://arcticdata.io/catalog/view/", identifier),
730+
`function` = "information")
731+
}
732+
733+
return(doc)
734+
}

man/eml_add_distribution.Rd

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test_eml.R

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,3 +404,20 @@ test_that('Datasets can be categorized', {
404404
expect_true(eml_validate(doc))
405405

406406
})
407+
408+
409+
test_that('Distribution info can be added', {
410+
411+
doc <- EML::read_eml(system.file("extdata/strix-pacific-northwest.xml", package="dataone"))
412+
# generate a doi
413+
id <- "test_id"
414+
doc <- eml_add_distribution(doc, id)
415+
416+
expect_true(eml_validate(doc))
417+
418+
expect_equal(doc$packageId, id)
419+
420+
expect_true(grepl(id, doc$dataset$distribution))
421+
422+
423+
})

0 commit comments

Comments
 (0)