From a70a23b20b175261217d13eceaa80eb0c134c843 Mon Sep 17 00:00:00 2001 From: Dominic Mullen Date: Thu, 5 Jul 2018 16:59:43 -0700 Subject: [PATCH 1/9] initial eml_otherEnt_to_dt commit --- R/eml.R | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/R/eml.R b/R/eml.R index 212138a..c3ca8df 100644 --- a/R/eml.R +++ b/R/eml.R @@ -979,3 +979,31 @@ eml_add_entities <- function(doc, doc } + +#' Convert otherEntities to dataTables +#' +#' Convert an EML 'otherEntity' object to a 'dataTable' object +#' +#' @param eml (S4) An EML S4 object +#' @param otherEntity (S4 / character) Either an EML otherEntity object or the index +#' of an otherEntity within a ListOfotherEntity +#' +#' @author Dominic Mullen dmullen17@@gmail.com +#' +#' @export +eml_otherEntity_to_dataTable <- function(eml, otherEntity) { + # argument checks + + # convert otherEntity to dataTable + dt <- capture.output(otherEntity) %>% + str_trim() %>% + str_replace_all("otherEntity", "dataTable") %>% + paste(sep = "", collapse = "") %>% + read_eml() + + # Add dt to bottom of dt list + + # delete otherEntity and update the lsit + + # return eml +} From 06fd03b41caf62d0b01c7cb762db342d527a25f8 Mon Sep 17 00:00:00 2001 From: Dominic Mullen Date: Fri, 6 Jul 2018 10:40:22 -0700 Subject: [PATCH 2/9] eml_otherEntity_to_dataTable function --- R/eml.R | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/R/eml.R b/R/eml.R index c3ca8df..00c5a2a 100644 --- a/R/eml.R +++ b/R/eml.R @@ -982,28 +982,53 @@ eml_add_entities <- function(doc, #' Convert otherEntities to dataTables #' -#' Convert an EML 'otherEntity' object to a 'dataTable' object +#' Convert an EML 'otherEntity' object to a 'dataTable' object. It converts the +#' otherEntity as currently constructed - it does not add a physical or add attributes. +#' However, if these are already in their respective slots, they will be retained. #' #' @param eml (S4) An EML S4 object #' @param otherEntity (S4 / character) Either an EML otherEntity object or the index #' of an otherEntity within a ListOfotherEntity +#' @param validate_eml (logical) Optional. Specify whether or not to validate the eml after +#' completion. Defaults to \code{TRUE}. Recommended setting is \code{TRUE}. Setting this to +#' \code{FALSE} reduces execution time by ~50%. #' #' @author Dominic Mullen dmullen17@@gmail.com #' #' @export -eml_otherEntity_to_dataTable <- function(eml, otherEntity) { - # argument checks +eml_otherEntity_to_dataTable <- function(eml, otherEntity, eml_validate = TRUE) { + ## Argument checks + stopifnot(isS4(eml)) + stopifnot(any(is.numeric(otherEntity), methods::is(otherEntity, "otherEntity"))) + + ## Handle different inputs for 'otherEntity' + if (is.numeric(otherEntity)) { + index <- otherEntity + otherEntity <- eml@dataset@otherEntity[[index]] + } else { + index <- datamgmt::which_in_eml(eml@dataset@otherEntity, + "entityName", + otherEntity@entityName) + } - # convert otherEntity to dataTable + ## convert otherEntity to dataTable dt <- capture.output(otherEntity) %>% str_trim() %>% str_replace_all("otherEntity", "dataTable") %>% paste(sep = "", collapse = "") %>% read_eml() - # Add dt to bottom of dt list + ## Add dt to bottom of dt list + type <- "dataTable" + slot(eml@dataset, type) <- new(paste0("ListOf", type), c(slot(eml@dataset, type), + new(paste0("ListOf", type), list(dt)))) - # delete otherEntity and update the lsit + ## delete otherEntity from list + eml@dataset@otherEntity[[index]] <- NULL - # return eml + ## return eml + if (validate_eml == TRUE) { + eml_validate(eml) + } + return(eml) } From 34199e20056625577856bec963977038432db01f Mon Sep 17 00:00:00 2001 From: Dominic Mullen Date: Fri, 6 Jul 2018 11:40:28 -0700 Subject: [PATCH 3/9] added unit tests --- R/eml.R | 6 +++++- tests/testthat/test_eml.R | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/R/eml.R b/R/eml.R index 00c5a2a..53d58e4 100644 --- a/R/eml.R +++ b/R/eml.R @@ -996,10 +996,11 @@ eml_add_entities <- function(doc, #' @author Dominic Mullen dmullen17@@gmail.com #' #' @export -eml_otherEntity_to_dataTable <- function(eml, otherEntity, eml_validate = TRUE) { +eml_otherEntity_to_dataTable <- function(eml, otherEntity, validate_eml = TRUE) { ## Argument checks stopifnot(isS4(eml)) stopifnot(any(is.numeric(otherEntity), methods::is(otherEntity, "otherEntity"))) + stopifnot(is.logical(validate_eml)) ## Handle different inputs for 'otherEntity' if (is.numeric(otherEntity)) { @@ -1009,6 +1010,9 @@ eml_otherEntity_to_dataTable <- function(eml, otherEntity, eml_validate = TRUE) index <- datamgmt::which_in_eml(eml@dataset@otherEntity, "entityName", otherEntity@entityName) + if (length(index) > 1) { + stop("Duplicate 'entityName' found in 'eml@dataset@otherEntity', please use a numeric index (1, 2, etc.) to specify which 'otherEntity' you would like to convert.") + } } ## convert otherEntity to dataTable diff --git a/tests/testthat/test_eml.R b/tests/testthat/test_eml.R index 9967a54..1813833 100644 --- a/tests/testthat/test_eml.R +++ b/tests/testthat/test_eml.R @@ -146,5 +146,41 @@ test_that("a dataTable and otherEntity can be added from a pid", { unlink(data_path) }) +test_that("eml_otherEntity_to_dataTable fails gracefully", { + if (!is_token_set(mn)) { + skip("No token set. Skipping test.") + } + + eml <- read_eml(system.file("example-eml.xml", package = "arcticdatautils")) + + # incorrect inputs + expect_error(eml_otherEntity_to_dataTable("dummy input")) + expect_error(eml_otherEntity_to_dataTable(eml, "1")) + + # subscripts out of bounds + expect_error(eml_otherEntity_to_dataTable(eml, eml@dataset@otherEntity[[2]])) + expect_error(eml_otherEntity_to_dataTable(eml, 2)) + + # Duplicate entityNames found + eml@dataset@otherEntity[[2]] <- eml@dataset@otherEntity[[1]] + expect_error(eml_otherEntity_to_dataTable(eml, eml@dataset@otherEntity[[1]])) + +}) + +test_that("eml_otherEntity_to_dataTable fails gracefully", { + if (!is_token_set(mn)) { + skip("No token set. Skipping test.") + } + + eml <- read_eml(system.file("example-eml.xml", package = "arcticdatautils")) + otherEntity <- eml@dataset@otherEntity[[1]] + eml <- eml_otherEntity_to_dataTable(eml, eml@dataset@otherEntity[[1]]) + # test that otherEntity was removed + expect_length(eml@dataset@otherEntity, 0) + + # test that dataTable was added + expect_equal(otherEntity@entityName, eml@dataset@dataTable[[1]]@entityName) + expect_equivalent(otherEntity@physical, eml@dataset@dataTable[[1]]@physical) +}) From b482759b73079c24a09ba9848d0603c314a01e2d Mon Sep 17 00:00:00 2001 From: Dominic Mullen Date: Fri, 6 Jul 2018 11:51:45 -0700 Subject: [PATCH 4/9] added examples --- R/eml.R | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/R/eml.R b/R/eml.R index 53d58e4..8991b33 100644 --- a/R/eml.R +++ b/R/eml.R @@ -987,8 +987,8 @@ eml_add_entities <- function(doc, #' However, if these are already in their respective slots, they will be retained. #' #' @param eml (S4) An EML S4 object -#' @param otherEntity (S4 / character) Either an EML otherEntity object or the index -#' of an otherEntity within a ListOfotherEntity +#' @param otherEntity (S4 / integer) Either an EML otherEntity object or the index +#' of an otherEntity within a ListOfotherEntity. Integer input is recommended. #' @param validate_eml (logical) Optional. Specify whether or not to validate the eml after #' completion. Defaults to \code{TRUE}. Recommended setting is \code{TRUE}. Setting this to #' \code{FALSE} reduces execution time by ~50%. @@ -996,10 +996,22 @@ eml_add_entities <- function(doc, #' @author Dominic Mullen dmullen17@@gmail.com #' #' @export +#' +#' @examples +#' \dontrun{ +#' eml <- read_eml(system.file("example-eml.xml", package = "arcticdatautils")) +#' +#' # The following two calls are equivalent: +#' eml <- eml_otherEntity_to_dataTable(eml, eml@@dataset@@otherEntity[[1]]) +#' eml <- eml_otherEntity_to_dataTable(eml, 1) +#' +#' # Integer input is recommended: +#' eml <- eml_otherEntity_to_dataTable(eml, 1) +#' } eml_otherEntity_to_dataTable <- function(eml, otherEntity, validate_eml = TRUE) { ## Argument checks stopifnot(isS4(eml)) - stopifnot(any(is.numeric(otherEntity), methods::is(otherEntity, "otherEntity"))) + stopifnot(any(is.integer(otherEntity), methods::is(otherEntity, "otherEntity"))) stopifnot(is.logical(validate_eml)) ## Handle different inputs for 'otherEntity' From 332d1a733e791eee584ffff8dee2d0d9018b689e Mon Sep 17 00:00:00 2001 From: Dominic Mullen Date: Fri, 6 Jul 2018 11:52:29 -0700 Subject: [PATCH 5/9] updated documentation --- NAMESPACE | 1 + ...create_dummy_enumeratedDomain_dataframe.Rd | 2 +- man/eml_otherEntity_to_dataTable.Rd | 38 +++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 man/eml_otherEntity_to_dataTable.Rd diff --git a/NAMESPACE b/NAMESPACE index 869a3fa..a4f19d4 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -18,6 +18,7 @@ export(eml_contact) export(eml_creator) export(eml_individual_name) export(eml_metadata_provider) +export(eml_otherEntity_to_dataTable) export(eml_party) export(eml_personnel) export(eml_project) diff --git a/man/create_dummy_enumeratedDomain_dataframe.Rd b/man/create_dummy_enumeratedDomain_dataframe.Rd index d65bc43..9cc8411 100644 --- a/man/create_dummy_enumeratedDomain_dataframe.Rd +++ b/man/create_dummy_enumeratedDomain_dataframe.Rd @@ -17,7 +17,7 @@ Create dummy enumeratedDomain data frame } \examples{ \dontrun{ -# Create dummy dataframe of 2 factors/enumerated domains +# Create dummy dataframe of 2 factors/enumerated domains attributes <- create_dummy_enumeratedDomain_dataframe(c("Factor1", "Factor2")) } } diff --git a/man/eml_otherEntity_to_dataTable.Rd b/man/eml_otherEntity_to_dataTable.Rd new file mode 100644 index 0000000..fe49fe4 --- /dev/null +++ b/man/eml_otherEntity_to_dataTable.Rd @@ -0,0 +1,38 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/eml.R +\name{eml_otherEntity_to_dataTable} +\alias{eml_otherEntity_to_dataTable} +\title{Convert otherEntities to dataTables} +\usage{ +eml_otherEntity_to_dataTable(eml, otherEntity, validate_eml = TRUE) +} +\arguments{ +\item{eml}{(S4) An EML S4 object} + +\item{otherEntity}{(S4 / integer) Either an EML otherEntity object or the index +of an otherEntity within a ListOfotherEntity. Integer input is recommended.} + +\item{validate_eml}{(logical) Optional. Specify whether or not to validate the eml after +completion. Defaults to \code{TRUE}. Recommended setting is \code{TRUE}. Setting this to +\code{FALSE} reduces execution time by ~50%.} +} +\description{ +Convert an EML 'otherEntity' object to a 'dataTable' object. It converts the +otherEntity as currently constructed - it does not add a physical or add attributes. +However, if these are already in their respective slots, they will be retained. +} +\examples{ +\dontrun{ +eml <- read_eml(system.file("example-eml.xml", package = "arcticdatautils")) + +# The following two calls are equivalent: +eml <- eml_otherEntity_to_dataTable(eml, eml@dataset@otherEntity[[1]]) +eml <- eml_otherEntity_to_dataTable(eml, 1) + +# Integer input is recommended: +eml <- eml_otherEntity_to_dataTable(eml, 1) +} +} +\author{ +Dominic Mullen dmullen17@gmail.com +} From 0ca6da560339d3c153e2035d925955cc6c99d665 Mon Sep 17 00:00:00 2001 From: Dominic Mullen Date: Fri, 6 Jul 2018 12:05:08 -0700 Subject: [PATCH 6/9] travis fixes --- DESCRIPTION | 1 + R/eml.R | 14 +++++++------- man/eml_otherEntity_to_dataTable.Rd | 6 +++--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1691b4d..e1c8308 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -37,5 +37,6 @@ Suggests: rmarkdown, yaml, xslt +Remotes: NCEAS/datamgmt RoxygenNote: 6.0.1 VignetteBuilder: knitr diff --git a/R/eml.R b/R/eml.R index 8991b33..520cc20 100644 --- a/R/eml.R +++ b/R/eml.R @@ -982,8 +982,8 @@ eml_add_entities <- function(doc, #' Convert otherEntities to dataTables #' -#' Convert an EML 'otherEntity' object to a 'dataTable' object. It converts the -#' otherEntity as currently constructed - it does not add a physical or add attributes. +#' Convert an EML 'otherEntity' object to a 'dataTable' object. This will convert an +#' otherEntity objectas currently constructed - it does not add a physical or add attributes. #' However, if these are already in their respective slots, they will be retained. #' #' @param eml (S4) An EML S4 object @@ -991,7 +991,7 @@ eml_add_entities <- function(doc, #' of an otherEntity within a ListOfotherEntity. Integer input is recommended. #' @param validate_eml (logical) Optional. Specify whether or not to validate the eml after #' completion. Defaults to \code{TRUE}. Recommended setting is \code{TRUE}. Setting this to -#' \code{FALSE} reduces execution time by ~50%. +#' \code{FALSE} reduces execution time by ~ 50 percent. #' #' @author Dominic Mullen dmullen17@@gmail.com #' @@ -1028,11 +1028,11 @@ eml_otherEntity_to_dataTable <- function(eml, otherEntity, validate_eml = TRUE) } ## convert otherEntity to dataTable - dt <- capture.output(otherEntity) %>% - str_trim() %>% - str_replace_all("otherEntity", "dataTable") %>% + dt <- utils::capture.output(otherEntity) %>% + stringr::str_trim() %>% + stringr::str_replace_all("otherEntity", "dataTable") %>% paste(sep = "", collapse = "") %>% - read_eml() + EML::read_eml() ## Add dt to bottom of dt list type <- "dataTable" diff --git a/man/eml_otherEntity_to_dataTable.Rd b/man/eml_otherEntity_to_dataTable.Rd index fe49fe4..83a1164 100644 --- a/man/eml_otherEntity_to_dataTable.Rd +++ b/man/eml_otherEntity_to_dataTable.Rd @@ -14,11 +14,11 @@ of an otherEntity within a ListOfotherEntity. Integer input is recommended.} \item{validate_eml}{(logical) Optional. Specify whether or not to validate the eml after completion. Defaults to \code{TRUE}. Recommended setting is \code{TRUE}. Setting this to -\code{FALSE} reduces execution time by ~50%.} +\code{FALSE} reduces execution time by ~ 50 percent.} } \description{ -Convert an EML 'otherEntity' object to a 'dataTable' object. It converts the -otherEntity as currently constructed - it does not add a physical or add attributes. +Convert an EML 'otherEntity' object to a 'dataTable' object. This will convert an +otherEntity objectas currently constructed - it does not add a physical or add attributes. However, if these are already in their respective slots, they will be retained. } \examples{ From f8e18ecd48c996c5a32206195174efc3e72af48c Mon Sep 17 00:00:00 2001 From: Dominic Mullen Date: Fri, 6 Jul 2018 12:31:36 -0700 Subject: [PATCH 7/9] more travis fixes --- DESCRIPTION | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index e1c8308..fbb8792 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -14,11 +14,13 @@ Description: A set of utilites for working with the Arctic Data Center Depends: R (>= 3.2.3) Imports: - digest, + datamgmt, dataone, datapack, + digest, EML, httr, + magrittr, methods, stringr, stringi, From b52283138614c01870ac171f4388dbc1b24a4bb1 Mon Sep 17 00:00:00 2001 From: Dominic Mullen Date: Fri, 6 Jul 2018 13:10:23 -0700 Subject: [PATCH 8/9] added mitchell's function --- DESCRIPTION | 2 - NAMESPACE | 1 + R/eml.R | 74 +++++++++++++++++++++++++++++++++++ man/which_in_eml.Rd | 41 ++++++++++++++++++++ tests/testthat/test_eml.R | 81 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 197 insertions(+), 2 deletions(-) create mode 100644 man/which_in_eml.Rd diff --git a/DESCRIPTION b/DESCRIPTION index fbb8792..e332b2e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -14,7 +14,6 @@ Description: A set of utilites for working with the Arctic Data Center Depends: R (>= 3.2.3) Imports: - datamgmt, dataone, datapack, digest, @@ -39,6 +38,5 @@ Suggests: rmarkdown, yaml, xslt -Remotes: NCEAS/datamgmt RoxygenNote: 6.0.1 VignetteBuilder: knitr diff --git a/NAMESPACE b/NAMESPACE index a4f19d4..16dada6 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -57,6 +57,7 @@ export(sysmeta_to_eml_physical) export(update_object) export(update_resource_map) export(view_profile) +export(which_in_eml) import(EML) import(XML) import(dataone) diff --git a/R/eml.R b/R/eml.R index 520cc20..b795ba0 100644 --- a/R/eml.R +++ b/R/eml.R @@ -1048,3 +1048,77 @@ eml_otherEntity_to_dataTable <- function(eml, otherEntity, validate_eml = TRUE) } return(eml) } + + +#' Search through EMLs +#' +#' This function returns indices within an EML list that contain an instance where \code{test == TRUE}. See examples for more information. +#' +#' @import EML +#' @param eml_list (S4/List) an EML list object +#' @param element (character) element to evaluate +#' @param test (function/character) A function to evaluate (see examples). If test is a character, will evaluate if \code{element == test} (see example 1). +#' +#' @keywords eml +#' +#' @author Mitchell Maier mitchell.maier@@gmail.com +#' +#' @examples +#' \dontrun{ +#' # Question: Which creators have a surName "Smith"? +#' n <- which_in_eml(eml@@dataset@@creator, "surName", "Smith") +#' # Answer: eml@@dataset@@creator[n] +#' +#' # Question: Which dataTables have an entityName that begins with "2016" +#' n <- which_in_eml(eml@@dataset@@dataTable, "entityName", function(x) {grepl("^2016", x)}) +#' # Answer: eml@@dataset@@dataTable[n] +#' +#' # Question: Which attributes in dataTable[[1]] have a numberType "natural"? +#' n <- which_in_eml(eml@@dataset@@dataTable[[1]]@@attributeList@@attribute, "numberType", "natural") +#' # Answer: eml@@dataset@@dataTable[[1]]@@attributeList@@attribute[n] +#' +#' #' # Question: Which dataTables have at least one attribute with a numberType "natural"? +#' n <- which_in_eml(eml@@dataset@@dataTable, "numberType", function(x) {"natural" %in% x}) +#' # Answer: eml@@dataset@@dataTable[n] +#' } +#' @export +#' +which_in_eml <- function(eml_list, element, test) { + + stopifnot(isS4(eml_list)) + stopifnot(methods::is(eml_list,"list")) + stopifnot(is.character(element)) + + if (is.character(test)) { + value = test + test = function(x) {x == value} + + } else { + stopifnot(is.function(test)) + } + + # Find location + location <- unlist(lapply(seq_along(eml_list), function(i) { + elements_test <- unlist(EML::eml_get(eml_list[[i]], element)) + + if (is.null(elements_test)) { + out <- NULL + + } else { + result <- test(elements_test) + + if (length(result) > 1) { + stop("Test must only return one value.") + + } else if (result == TRUE) { + out <- i + + } else { + out <- NULL + } + } + return(out) + })) + + return(location) +} diff --git a/man/which_in_eml.Rd b/man/which_in_eml.Rd new file mode 100644 index 0000000..4e56266 --- /dev/null +++ b/man/which_in_eml.Rd @@ -0,0 +1,41 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/eml.R +\name{which_in_eml} +\alias{which_in_eml} +\title{Search through EMLs} +\usage{ +which_in_eml(eml_list, element, test) +} +\arguments{ +\item{eml_list}{(S4/List) an EML list object} + +\item{element}{(character) element to evaluate} + +\item{test}{(function/character) A function to evaluate (see examples). If test is a character, will evaluate if \code{element == test} (see example 1).} +} +\description{ +This function returns indices within an EML list that contain an instance where \code{test == TRUE}. See examples for more information. +} +\examples{ +\dontrun{ +# Question: Which creators have a surName "Smith"? +n <- which_in_eml(eml@dataset@creator, "surName", "Smith") +# Answer: eml@dataset@creator[n] + +# Question: Which dataTables have an entityName that begins with "2016" +n <- which_in_eml(eml@dataset@dataTable, "entityName", function(x) {grepl("^2016", x)}) +# Answer: eml@dataset@dataTable[n] + +# Question: Which attributes in dataTable[[1]] have a numberType "natural"? +n <- which_in_eml(eml@dataset@dataTable[[1]]@attributeList@attribute, "numberType", "natural") +# Answer: eml@dataset@dataTable[[1]]@attributeList@attribute[n] + +#' # Question: Which dataTables have at least one attribute with a numberType "natural"? +n <- which_in_eml(eml@dataset@dataTable, "numberType", function(x) {"natural" \%in\% x}) +# Answer: eml@dataset@dataTable[n] +} +} +\author{ +Mitchell Maier mitchell.maier@gmail.com +} +\keyword{eml} diff --git a/tests/testthat/test_eml.R b/tests/testthat/test_eml.R index 1813833..06e39b8 100644 --- a/tests/testthat/test_eml.R +++ b/tests/testthat/test_eml.R @@ -184,3 +184,84 @@ test_that("eml_otherEntity_to_dataTable fails gracefully", { expect_equal(otherEntity@entityName, eml@dataset@dataTable[[1]]@entityName) expect_equivalent(otherEntity@physical, eml@dataset@dataTable[[1]]@physical) }) + +test_that("which_in_eml Returns correct locations", { + if (!is_token_set(mn)) { + skip("No token set. Skipping test.") + } + + attributes <- + data.frame( + attributeName = c( + "length_1", + "time_2", + "length_3"), + attributeDefinition = c( + "def 1", + "def 2", + "def 3"), + formatString = c( + NA, + NA, + NA), + measurementScale = c( + "ratio", + "ratio", + "ratio"), + domain = c( + "numericDomain", + "numericDomain", + "numericDomain"), + definition = c( + NA, + NA, + NA), + unit = c( + "meter", + "second", + "meter"), + numberType = c( + "real", + "real", + "real"), + stringsAsFactors = FALSE + ) + + attributeList <- EML::set_attributes(attributes) + + dataTable_1 <- new("dataTable", + entityName = "2016_data.csv", + entityDescription = "2016 data", + attributeList = attributeList) + + dataTable_2 <- dataTable_1 + + dataTable_3 <- new("dataTable", + entityName = "2015_data.csv", + entityDescription = "2016 data", + attributeList = attributeList) + + creator_1 <- new("creator", + individualName = new("individualName", + surName = "LAST", + givenName = "FIRST")) + creator_2 <- new("creator", + individualName = new("individualName", + surName = "LAST", + givenName = "FIRST_2")) + creator_3 <- creator_2 + + title <- "Title" + + dataset <- new("dataset", + title = title, + creator = c(creator_1, creator_2, creator_3), + dataTable = c(dataTable_1, dataTable_2, dataTable_3)) + + eml <- new("eml", + dataset = dataset) + + expect_equal(c(2,3), which_in_eml(eml@dataset@creator, "givenName", "FIRST_2")) + expect_error(which_in_eml(eml@dataset@dataTable, "attributeName", "length_3")) + expect_equal(c(1,3), which_in_eml(eml@dataset@dataTable[[1]]@attributeList@attribute, "attributeName", function(x) {grepl("^length", x)})) +}) From 0012d2855f11642fb2394ca955240f3ff8c4c3be Mon Sep 17 00:00:00 2001 From: Dominic Mullen Date: Fri, 6 Jul 2018 13:13:30 -0700 Subject: [PATCH 9/9] syntax updates --- R/eml.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/eml.R b/R/eml.R index b795ba0..cf2e850 100644 --- a/R/eml.R +++ b/R/eml.R @@ -1010,7 +1010,7 @@ eml_add_entities <- function(doc, #' } eml_otherEntity_to_dataTable <- function(eml, otherEntity, validate_eml = TRUE) { ## Argument checks - stopifnot(isS4(eml)) + stopifnot(methods::is(eml, "eml")) stopifnot(any(is.integer(otherEntity), methods::is(otherEntity, "otherEntity"))) stopifnot(is.logical(validate_eml)) @@ -1019,9 +1019,9 @@ eml_otherEntity_to_dataTable <- function(eml, otherEntity, validate_eml = TRUE) index <- otherEntity otherEntity <- eml@dataset@otherEntity[[index]] } else { - index <- datamgmt::which_in_eml(eml@dataset@otherEntity, - "entityName", - otherEntity@entityName) + index <- which_in_eml(eml@dataset@otherEntity, + "entityName", + otherEntity@entityName) if (length(index) > 1) { stop("Duplicate 'entityName' found in 'eml@dataset@otherEntity', please use a numeric index (1, 2, etc.) to specify which 'otherEntity' you would like to convert.") }