Skip to content

Commit

Permalink
add test for set_project; add unit test for optional eml element tests (
Browse files Browse the repository at this point in the history
#144)

* Add test for set_project

* add unit tests for optional eml elements: test_pii_meta_emails, test_notes

* update test_project inform message

* add minimal unit tests for each function in optional_eml_elements.R

* add test_project to optional eml items tests for DataStore

* Add test_project to list of optional items tested.

* update documentation

* update news to include set_project tests

* fix typo in set_data_urls error message

* updated via pkgdown

* remove extraneous documentation

* auto update via pkgdown::build_github_site_pages and devtools::document
  • Loading branch information
RobLBaker authored Sep 19, 2024
1 parent b96b6d5 commit e8c6cb4
Show file tree
Hide file tree
Showing 99 changed files with 12,381 additions and 2,437 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
53 changes: 53 additions & 0 deletions R/optional_eml_elements.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

11 changes: 10 additions & 1 deletion R/run_checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)")
Expand Down
2 changes: 1 addition & 1 deletion R/tabular_data_congruence.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
53 changes: 22 additions & 31 deletions docs/404.html

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

47 changes: 19 additions & 28 deletions docs/LICENSE-text.html

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

Loading

0 comments on commit e8c6cb4

Please sign in to comment.