diff --git a/DESCRIPTION b/DESCRIPTION index b3458b5..b1ba80f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -10,7 +10,7 @@ Description: Allows the user (and reviewer) to check a data package and test whe License: CC0 Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 VignetteBuilder: knitr Suggests: here, diff --git a/NAMESPACE b/NAMESPACE index 4890f32..ba3236c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -39,6 +39,7 @@ export(test_orcid_match) export(test_orcid_resolves) export(test_pii_data_emails) export(test_pii_meta_emails) +export(test_project) export(test_pub_date) export(test_public_points) export(test_publisher) diff --git a/NEWS.md b/NEWS.md index 7716cbf..28aacbc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +# DPchecker 0.3.5 (develoment version) +* Add `test_project()` function to test for DataStore projects. +* Add unit tests for all optional eml elements +* Update documentation to reflect new `test_project()` function. + # DPchecker 0.3.4 2024-07-29 diff --git a/R/optional_eml_elements.R b/R/optional_eml_elements.R index 7eafff1..3509d01 100644 --- a/R/optional_eml_elements.R +++ b/R/optional_eml_elements.R @@ -503,3 +503,56 @@ test_public_points <- function(metadata = load_metadata(directory)){ } return(invisible(metadata)) } + + +#' Test for a DataStore project +#' +#' @inheritParams test_pub_date +#' +#' @return invisible(metadata) +#' @export +#' +#' @examples +#' \dontrun{ +#' test_project() +#' } +test_project <- function (metadata = load_metadata(directory)) { + #check whether EML is schema valid + is_eml(metadata) + #get project element + proj <- metadata[["dataset"]][["project"]] + + #if there is no project information: + missing_proj <- is.null(proj) + if (missing_proj) { + msg <- paste0("No project associated with the metadata. ", + "To add a DataStore project, use ", + "{.fun EMLeditor::set_project}.") + cli::cli_warn(c("!" = msg)) + return(invisible(metadata)) + } + + #drop `@context` item from proj + proj$`@context` <- NULL + + # If there's only project coverage element, proj ends up with one less level of nesting. Re-nest it so that the rest of the code works consistently + relist <- ("title" %in% names(proj) | "references" %in% names(proj)) + if (relist) { + proj <- list(proj) + } + + #if there are projects, but no DataStore project: + proj_test <- unlist(proj) + DS_proj <- "id" %in% names(proj_test) + if (!DS_proj) { + msg <- paste0("No project associated with the metadata. ", + "To add a DataStore project, use ", + "{.fun EMLeditor::set_project}.") + cli::cli_warn(c("!" = msg)) + return(invisible(metadata)) + } + + msg <- "The metadata contains at least one DataStore Project reference." + cli::cli_inform(c("v" = msg)) +} + diff --git a/R/run_checks.R b/R/run_checks.R index 0854d94..9eb7823 100644 --- a/R/run_checks.R +++ b/R/run_checks.R @@ -363,7 +363,7 @@ run_congruence_checks <- function(directory = here::here(), cli::cli_bullets(c(w$message, w$body)) }) - cli::cli_h2("Checking additional metadata elements") + cli::cli_h2("Checking additional/optional metadata elements") tryCatch(test_orcid_exists(metadata), error = function(e) { @@ -410,6 +410,15 @@ run_congruence_checks <- function(directory = here::here(), warn_count <<- warn_count + 1 cli::cli_bullets(c(w$message, w$body)) }) + tryCatch(test_project(metadata), + error = function(e) { + err_count <<- err_count +1 + cli::cli_bullets(c(e$message, e$body)) + }, + warning = function(w) { + warn_count <<- warn_count +1 + cli::cli_bullets(c(w$message, w$body)) + }) if (!check_metadata_only) { cli::cli_h2("Checking that metadata is consistent with data file(s)") diff --git a/R/tabular_data_congruence.R b/R/tabular_data_congruence.R index 63f84f1..3dd4e16 100644 --- a/R/tabular_data_congruence.R +++ b/R/tabular_data_congruence.R @@ -381,7 +381,7 @@ test_datatable_urls <- function (metadata = load_metadata(directory)) { } else { # really only need to say it once per file/column combo msg <- err_log - err <- paste0("Metadata lacks URL(s) for the following dtata files. Use {.fn EMLeditor::set_data_urls} to add them.") + err <- paste0("Metadata lacks URL(s) for the following data files. Use {.fn EMLeditor::set_data_urls} to add them.") cli::cli_abort(c("x" = err, msg)) } return(invisible(metadata)) diff --git a/docs/404.html b/docs/404.html index 2fc3aef..288f273 100644 --- a/docs/404.html +++ b/docs/404.html @@ -8,55 +8,46 @@ Page not found (404) • DPchecker - - - - + + + Skip to contents - -