From a938752b0df3e39b25917f2274214d041043e330 Mon Sep 17 00:00:00 2001 From: Irene <25118334+isteves@users.noreply.github.com> Date: Wed, 9 May 2018 12:08:48 -0700 Subject: [PATCH 01/14] Add EML object as an alternative option for metadata_path in publish_update --- R/editing.R | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/R/editing.R b/R/editing.R index e3a1b77..40bf436 100644 --- a/R/editing.R +++ b/R/editing.R @@ -233,7 +233,7 @@ update_object <- function(mn, pid, path, format_id=NULL, new_pid=NULL, sid=NULL) #' @param parent_data_pids (character) Optional. Identifier for the data objects of the parent package. Not optional if the parent package contains data objects. #' @param parent_child_pids (character) Optional. Resource map identifier(s) of child packages in the parent package. \code{resource_map_pid} should not be included. Not optional if the parent package contains other child packages. #' @param child_pids (character) Optional. Child packages resource map PIDs. -#' @param metadata_path (character) Optional. Path to a metadata file to update with. If this is not set, the existing metadata document will be used. +#' @param metadata_path (character or eml) Optional. An eml class object or a path to a metadata file to update with. If this is not set, the existing metadata document will be used. #' @param public (logical) Optional. Make the update public. If FALSE, will set the metadata and resource map to private (but not the data objects). #' This applies to the new metadata PID and its resource map and data object. #' access policies are not affected. @@ -367,6 +367,15 @@ publish_update <- function(mn, # Get the metadata doc message("Getting metadata from the MN.") eml <- EML::read_eml(rawToChar(dataone::getObject(mn, metadata_pid)), asText = TRUE) + + } if(class(metadata_path) == "eml") { + # If an eml object is provided, use it directly after validating + if(!eml_validate(metadata_path)){ + stop("The EML object is not valid.") + } + + eml <- metadata_path + } else { # Alternatively, read an edited metadata file from disk if provided if (!file.exists(metadata_path)) { From c8287fbd8e2a4c2d3e933996a2047a50c9cc6d12 Mon Sep 17 00:00:00 2001 From: Irene <25118334+isteves@users.noreply.github.com> Date: Wed, 9 May 2018 13:32:21 -0700 Subject: [PATCH 02/14] fixed ifelse --- R/editing.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/R/editing.R b/R/editing.R index 40bf436..c1edeb1 100644 --- a/R/editing.R +++ b/R/editing.R @@ -368,13 +368,13 @@ publish_update <- function(mn, message("Getting metadata from the MN.") eml <- EML::read_eml(rawToChar(dataone::getObject(mn, metadata_pid)), asText = TRUE) - } if(class(metadata_path) == "eml") { - # If an eml object is provided, use it directly after validating - if(!eml_validate(metadata_path)){ - stop("The EML object is not valid.") - } + } else if(class(metadata_path) == "eml") { + # If an eml object is provided, use it directly after validating + if(!eml_validate(metadata_path)){ + stop("The EML object is not valid.") + } - eml <- metadata_path + eml <- metadata_path } else { # Alternatively, read an edited metadata file from disk if provided From 57812840c29fe6c429432c89f0499626ae0e2ed0 Mon Sep 17 00:00:00 2001 From: Irene <25118334+isteves@users.noreply.github.com> Date: Wed, 9 May 2018 13:32:28 -0700 Subject: [PATCH 03/14] updated man --- man/publish_update.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/publish_update.Rd b/man/publish_update.Rd index 3aaf5ba..76f4508 100644 --- a/man/publish_update.Rd +++ b/man/publish_update.Rd @@ -21,7 +21,7 @@ publish_update(mn, metadata_pid, resource_map_pid, data_pids = NULL, \item{child_pids}{(character) Optional. Child packages resource map PIDs.} -\item{metadata_path}{(character) Optional. Path to a metadata file to update with. If this is not set, the existing metadata document will be used.} +\item{metadata_path}{(character or eml) Optional. An eml class object or a path to a metadata file to update with. If this is not set, the existing metadata document will be used.} \item{identifier}{(character) Manually specify the identifier for the new metadata object.} From 2710025b1079ccb95d295de58098ab8a7d16fcfb Mon Sep 17 00:00:00 2001 From: Irene <25118334+isteves@users.noreply.github.com> Date: Wed, 9 May 2018 14:06:18 -0700 Subject: [PATCH 04/14] Try uncaching packages to see if devel/new release will work https://stat.ethz.ch/pipermail/r-sig-debian/2018-April/002829.html https://github.com/r-spatial/sf/issues/729 https://github.com/Rdatatable/data.table/issues/2801 --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a4c91ba..da0bf51 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,6 @@ r: - release - devel sudo: false -cache: packages addons: apt: packages: From ac32bf34c536aa33eaa221d8b46211165f564330 Mon Sep 17 00:00:00 2001 From: isteves <25118334+isteves@users.noreply.github.com> Date: Wed, 9 May 2018 15:27:58 -0700 Subject: [PATCH 05/14] Try `update: true` Added `cache: packages` back in --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index da0bf51..03dd703 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,8 +6,10 @@ r: - release - devel sudo: false +cache: packages addons: apt: + update: true packages: - librdf0-dev - libnetcdf-dev From ccdfa2082d240ed892cb398c2a9e0f112be6a060 Mon Sep 17 00:00:00 2001 From: Bryce Mecum Date: Thu, 10 May 2018 15:02:48 -0700 Subject: [PATCH 06/14] Reduce dependencies on ncdf4 and yaml @isteves helpfully noted that the Travis CI builds started failing a while ago in https://github.com/NCEAS/arcticdatautils/issues/86. The failures indicate issues with Ubuntu PPAs and nothing to do with our tools. Though this happened around the time R 3.5.0 was released, which is a backwards incompatible R release indue to the introduction of ALTREP. This is: 1. My attempt to fix that so all the Travis builds pass 2. Reduce the deps arcticdatautils requires to install. ncdf4 and yaml are not packages that _need_ to be installed to get started using it so they should be in Suggests --- .travis.yml | 2 -- DESCRIPTION | 4 ++-- R/attributes.R | 6 ++++++ R/environment.R | 6 ++++++ R/util.R | 6 ++++++ 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index a4c91ba..835edf6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,5 +11,3 @@ addons: apt: packages: - librdf0-dev - - libnetcdf-dev - - r-cran-ncdf4 diff --git a/DESCRIPTION b/DESCRIPTION index 67fdc2e..ac8d1f5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -21,12 +21,10 @@ Imports: EML, httr, methods, - ncdf4, stringr, stringi, tools, uuid, - yaml, xml2, XML License: MIT + file LICENSE @@ -35,7 +33,9 @@ Suggests: testthat, humaniformat, knitr, + ncdf4, rmarkdown, + yaml, xslt RoxygenNote: 6.0.1 VignetteBuilder: knitr diff --git a/R/attributes.R b/R/attributes.R index 8042a40..fed08e6 100644 --- a/R/attributes.R +++ b/R/attributes.R @@ -12,6 +12,12 @@ get_ncdf4_attributes <- function(nc) { stopifnot(is(nc, "ncdf4") || file.exists(nc)) + if (!requireNamespace("ncdf4")) { + stop(call. = FALSE, + "The package 'ncdf4' must be installed to run this function. ", + "Please install it and try again.") + } + # Read the file in if `nc` is a character vector if (is.character(nc)) { nc <- ncdf4::nc_open(nc) diff --git a/R/environment.R b/R/environment.R index 8ff1c12..66c32aa 100644 --- a/R/environment.R +++ b/R/environment.R @@ -38,6 +38,12 @@ env_get <- function() { #' #' env_load <- function(name=NULL, path=NULL, skip_mn=FALSE) { + if (!requireNamespace("yaml")) { + stop(call. = FALSE, + "The package 'yaml' must be installed to run this function. ", + "Please install it and try again.") + } + # Determine the environment to load if (is.null(name)) { name <- env_get() diff --git a/R/util.R b/R/util.R index eaa5001..2ef7984 100644 --- a/R/util.R +++ b/R/util.R @@ -109,6 +109,12 @@ get_netcdf_format_id <- function(path) { nchar(path) > 0, file.exists(path)) + if (!requireNamespace("ncdf4")) { + stop(call. = FALSE, + "The package 'ncdf4' must be installed to run this function. ", + "Please install it and try again.") + } + # Try to open the file, capturing errors cdf_file <- try({ ncdf4::nc_open(path) From 431593e088e234919e4bf88300d501f62227a62f Mon Sep 17 00:00:00 2001 From: Bryce Mecum Date: Thu, 10 May 2018 15:26:04 -0700 Subject: [PATCH 07/14] Turn off forcing suggests in travis build --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 835edf6..fcd9c84 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,8 @@ r: - release - devel sudo: false +env: + - _R_CHECK_FORCE_SUGGESTS_=0 cache: packages addons: apt: From 9e0ea67708deccee4c3dd635e0b843b72cbedef6 Mon Sep 17 00:00:00 2001 From: Bryce Mecum Date: Thu, 10 May 2018 15:42:41 -0700 Subject: [PATCH 08/14] Move dplyr to Suggests --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index ac8d1f5..1cddca5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -15,7 +15,6 @@ Depends: R (>= 3.2.3) Imports: digest, - dplyr, dataone, datapack, EML, @@ -30,6 +29,7 @@ Imports: License: MIT + file LICENSE LazyData: true Suggests: + dplyr, testthat, humaniformat, knitr, From 77ef74f042374cc334efe1d60f8a745ac71f1a3c Mon Sep 17 00:00:00 2001 From: Bryce Mecum Date: Thu, 10 May 2018 15:52:10 -0700 Subject: [PATCH 09/14] Incorporate carl's great ideas https://github.com/NCEAS/arcticdatautils/pull/88#issuecomment-388208858 --- .travis.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index fcd9c84..aee4c81 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,11 +5,13 @@ r: - oldrel - release - devel +r_packages: ncdf4 sudo: false -env: - - _R_CHECK_FORCE_SUGGESTS_=0 cache: packages addons: apt: + update: true packages: - librdf0-dev + - libnetcdf-dev + - netcdf-bin From 0554abe993ee1e09a0449d5bb26a8ee3aa5d9412 Mon Sep 17 00:00:00 2001 From: Irene <25118334+isteves@users.noreply.github.com> Date: Wed, 9 May 2018 12:08:48 -0700 Subject: [PATCH 10/14] Add EML object as an alternative option for metadata_path in publish_update --- R/editing.R | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/R/editing.R b/R/editing.R index e3a1b77..40bf436 100644 --- a/R/editing.R +++ b/R/editing.R @@ -233,7 +233,7 @@ update_object <- function(mn, pid, path, format_id=NULL, new_pid=NULL, sid=NULL) #' @param parent_data_pids (character) Optional. Identifier for the data objects of the parent package. Not optional if the parent package contains data objects. #' @param parent_child_pids (character) Optional. Resource map identifier(s) of child packages in the parent package. \code{resource_map_pid} should not be included. Not optional if the parent package contains other child packages. #' @param child_pids (character) Optional. Child packages resource map PIDs. -#' @param metadata_path (character) Optional. Path to a metadata file to update with. If this is not set, the existing metadata document will be used. +#' @param metadata_path (character or eml) Optional. An eml class object or a path to a metadata file to update with. If this is not set, the existing metadata document will be used. #' @param public (logical) Optional. Make the update public. If FALSE, will set the metadata and resource map to private (but not the data objects). #' This applies to the new metadata PID and its resource map and data object. #' access policies are not affected. @@ -367,6 +367,15 @@ publish_update <- function(mn, # Get the metadata doc message("Getting metadata from the MN.") eml <- EML::read_eml(rawToChar(dataone::getObject(mn, metadata_pid)), asText = TRUE) + + } if(class(metadata_path) == "eml") { + # If an eml object is provided, use it directly after validating + if(!eml_validate(metadata_path)){ + stop("The EML object is not valid.") + } + + eml <- metadata_path + } else { # Alternatively, read an edited metadata file from disk if provided if (!file.exists(metadata_path)) { From 24b3c201e83d8389bce8b53fff1ea8a3893d04aa Mon Sep 17 00:00:00 2001 From: Irene <25118334+isteves@users.noreply.github.com> Date: Wed, 9 May 2018 13:32:21 -0700 Subject: [PATCH 11/14] fixed ifelse --- R/editing.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/R/editing.R b/R/editing.R index 40bf436..c1edeb1 100644 --- a/R/editing.R +++ b/R/editing.R @@ -368,13 +368,13 @@ publish_update <- function(mn, message("Getting metadata from the MN.") eml <- EML::read_eml(rawToChar(dataone::getObject(mn, metadata_pid)), asText = TRUE) - } if(class(metadata_path) == "eml") { - # If an eml object is provided, use it directly after validating - if(!eml_validate(metadata_path)){ - stop("The EML object is not valid.") - } + } else if(class(metadata_path) == "eml") { + # If an eml object is provided, use it directly after validating + if(!eml_validate(metadata_path)){ + stop("The EML object is not valid.") + } - eml <- metadata_path + eml <- metadata_path } else { # Alternatively, read an edited metadata file from disk if provided From f33cf75787730e660306d481a3adaf45be4e4f25 Mon Sep 17 00:00:00 2001 From: Irene <25118334+isteves@users.noreply.github.com> Date: Wed, 9 May 2018 13:32:28 -0700 Subject: [PATCH 12/14] updated man --- man/publish_update.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/publish_update.Rd b/man/publish_update.Rd index 3aaf5ba..76f4508 100644 --- a/man/publish_update.Rd +++ b/man/publish_update.Rd @@ -21,7 +21,7 @@ publish_update(mn, metadata_pid, resource_map_pid, data_pids = NULL, \item{child_pids}{(character) Optional. Child packages resource map PIDs.} -\item{metadata_path}{(character) Optional. Path to a metadata file to update with. If this is not set, the existing metadata document will be used.} +\item{metadata_path}{(character or eml) Optional. An eml class object or a path to a metadata file to update with. If this is not set, the existing metadata document will be used.} \item{identifier}{(character) Manually specify the identifier for the new metadata object.} From 8346ada8973ba78508dbb28b0ca77a8b06c59b4c Mon Sep 17 00:00:00 2001 From: Irene <25118334+isteves@users.noreply.github.com> Date: Wed, 9 May 2018 14:06:18 -0700 Subject: [PATCH 13/14] Try uncaching packages to see if devel/new release will work https://stat.ethz.ch/pipermail/r-sig-debian/2018-April/002829.html https://github.com/r-spatial/sf/issues/729 https://github.com/Rdatatable/data.table/issues/2801 --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index aee4c81..ee18f4c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,6 @@ r: - devel r_packages: ncdf4 sudo: false -cache: packages addons: apt: update: true From 96ae41fce845f5262c418431c78cc49f0f4c6d4a Mon Sep 17 00:00:00 2001 From: isteves <25118334+isteves@users.noreply.github.com> Date: Wed, 9 May 2018 15:27:58 -0700 Subject: [PATCH 14/14] Try `update: true` Added `cache: packages` back in --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index ee18f4c..aee4c81 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ r: - devel r_packages: ncdf4 sudo: false +cache: packages addons: apt: update: true