From 2b6fc8d98470ca5bb433298d683a124c6e4a415b Mon Sep 17 00:00:00 2001 From: Rob Baker Date: Tue, 17 Sep 2024 08:48:51 -0600 Subject: [PATCH 01/12] Add test for set_project --- R/optional_eml_elements.R | 53 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/R/optional_eml_elements.R b/R/optional_eml_elements.R index 7eafff1..911b71a 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 contain a DataStore Project reference." + cli::cli_inform(c("v" = msg)) +} + From 246ac20202aa50e038e76343f5d0d5256a6dadae Mon Sep 17 00:00:00 2001 From: Rob Baker Date: Tue, 17 Sep 2024 14:38:39 -0600 Subject: [PATCH 02/12] add unit tests for optional eml elements: test_pii_meta_emails, test_notes --- tests/testthat/test-optional_eml_elements.R | 26 +++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tests/testthat/test-optional_eml_elements.R diff --git a/tests/testthat/test-optional_eml_elements.R b/tests/testthat/test-optional_eml_elements.R new file mode 100644 index 0000000..75c03e9 --- /dev/null +++ b/tests/testthat/test-optional_eml_elements.R @@ -0,0 +1,26 @@ +good_dir <- test_path("good") +bad_dir <- test_path("bad") +bicy_meta <- load_metadata(test_path("good", "BICY_good")) +buis_meta <- load_metadata(test_path("good", "BUIS_good")) + +# ---- load_metadata ---- +test_that("load_metadata works on valid EML file", { + expect_message(load_metadata(here::here(good_dir, "BICY_good"), inform_success = TRUE), + ".*Metadata check passed.*") + expect_message(load_metadata(here::here(good_dir, "BUIS_good"), inform_success = TRUE), + ".*Metadata check passed.*") +}) + +# ---- test_pii_meta_emails + +test_that("test_pii_meta_emails finds true negatives", { + expect_message(test_pii_meta_emails(here::here(good_dir, "BICY_good")), "Metadata does not appear to contain any personal emails") +}) + +# ---- test_notes +test_that("test_notes correctly warns when no notes present", { + expect_warning(test_notes(metadata = bicy_meta), "Metadata does not contain additionalInfo*") +}) + + +# ---- test_methods From aa4b72301d533bdbbbed7fd50f1ceecb5d4eb4fb Mon Sep 17 00:00:00 2001 From: Rob Baker Date: Thu, 19 Sep 2024 09:26:47 -0600 Subject: [PATCH 03/12] update test_project inform message --- R/optional_eml_elements.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/optional_eml_elements.R b/R/optional_eml_elements.R index 911b71a..3509d01 100644 --- a/R/optional_eml_elements.R +++ b/R/optional_eml_elements.R @@ -552,7 +552,7 @@ test_project <- function (metadata = load_metadata(directory)) { return(invisible(metadata)) } - msg <- "The metadata contain a DataStore Project reference." + msg <- "The metadata contains at least one DataStore Project reference." cli::cli_inform(c("v" = msg)) } From 85de26330ce10f2572bb2bb970062c2344fe5d43 Mon Sep 17 00:00:00 2001 From: Rob Baker Date: Thu, 19 Sep 2024 09:27:08 -0600 Subject: [PATCH 04/12] add minimal unit tests for each function in optional_eml_elements.R --- tests/testthat/test-optional_eml_elements.R | 94 ++++++++++++++++++--- 1 file changed, 80 insertions(+), 14 deletions(-) diff --git a/tests/testthat/test-optional_eml_elements.R b/tests/testthat/test-optional_eml_elements.R index 75c03e9..f0333f4 100644 --- a/tests/testthat/test-optional_eml_elements.R +++ b/tests/testthat/test-optional_eml_elements.R @@ -3,24 +3,90 @@ bad_dir <- test_path("bad") bicy_meta <- load_metadata(test_path("good", "BICY_good")) buis_meta <- load_metadata(test_path("good", "BUIS_good")) -# ---- load_metadata ---- -test_that("load_metadata works on valid EML file", { - expect_message(load_metadata(here::here(good_dir, "BICY_good"), inform_success = TRUE), - ".*Metadata check passed.*") - expect_message(load_metadata(here::here(good_dir, "BUIS_good"), inform_success = TRUE), - ".*Metadata check passed.*") -}) - # ---- test_pii_meta_emails -test_that("test_pii_meta_emails finds true negatives", { - expect_message(test_pii_meta_emails(here::here(good_dir, "BICY_good")), "Metadata does not appear to contain any personal emails") -}) +test_that("test_pii_meta_emails finds true negatives", + { + msg <- "Metadata does not appear to contain any personal emails" + expect_message(test_pii_meta_emails(here::here(good_dir, + "BICY_good")), + msg) + } + ) # ---- test_notes -test_that("test_notes correctly warns when no notes present", { - expect_warning(test_notes(metadata = bicy_meta), "Metadata does not contain additionalInfo*") -}) +test_that("test_notes correctly warns when no notes present", + { + expect_warning(test_notes(metadata = bicy_meta), + "Metadata does not contain additionalInfo*") + } + ) # ---- test_methods + +test_that("test_methods identifies presence of non-standard characters", + { + msg <- paste0("The metadata methods contains ", + "non-standard characters such as*") + expect_warning(test_methods(metadata = bicy_meta), + msg) + } + ) + +# ---- test_orcid_exists + +test_that("test_orcid_exists correctly identifies orcids exist", + { + expect_message(test_orcid_exists(metadata = bicy_meta), + "All individual creators have associated ORCiDs.") +}) + +# ---- test_orcid_format + +test_that("test_orcid_format identifies properly formatted orcids", + { + expect_message(test_orcid_format(metadata = bicy_meta), + "All Creator ORCiDs are properly formatted.") + } + ) + +# ---- test_orcid_resolves + +# ----- test_orcid_resolves ---- +test_that("test_orcid_resolves correctly identifies orcids that resolve", + { + msg <- "All Creator ORCiDs resolved to a valid ORCiD profile." + expect_message(test_orcid_resolves(metadata = bicy_meta), + msg) + } + ) + +# ---- test_orcid_match +test_that("test_orcid_match correctly identifies when orcid and crearot match", + { + msg <- paste0("All Creator ORCiDs resolve to an ORCiD profile ", + "that matches the Creator last name.") + expect_message(test_orcid_match(metadata = bicy_meta), + msg) + } + ) + +# ---- test_public_points +test_that("test_public_points warns GPS points exist in restricted metadata", + { + msg <- paste0("CUI is not set to PUBLIC. GPS coordinates detected ", + "in metadata will be publicly available. ", + "Are you sure?") + expect_warning(test_public_points(metadata = bicy_meta), + msg) + } + ) + +# ---- test_project +test_that("test_project warns when no project is present", + { + expect_warning(test_project(metadata = bicy_meta), + "No project associated with the metadata.*") + } + ) From fa14b2c4617382a6edba8d3e7db9ca761cd1270c Mon Sep 17 00:00:00 2001 From: Rob Baker Date: Thu, 19 Sep 2024 09:39:13 -0600 Subject: [PATCH 05/12] add test_project to optional eml items tests for DataStore --- R/run_checks.R | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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)") From ee81623a55dcc42fa6f117e442a338d461af8cb8 Mon Sep 17 00:00:00 2001 From: Rob Baker Date: Thu, 19 Sep 2024 09:40:50 -0600 Subject: [PATCH 06/12] Add test_project to list of optional items tested. --- vignettes/DPchecker.Rmd | 1 + 1 file changed, 1 insertion(+) diff --git a/vignettes/DPchecker.Rmd b/vignettes/DPchecker.Rmd index c42a4db..88c1994 100644 --- a/vignettes/DPchecker.Rmd +++ b/vignettes/DPchecker.Rmd @@ -124,6 +124,7 @@ These elements aren't required. If they are missing, the tests will generate a w * All ORCiDs resolve to an ORCiD profile ([`test_orcid_resolves()`](../reference/test_orcid_resolves.html)) * All ORCiDs resolve to an ORCiD profile that matches the Creator's last name ([`test_orcid_match()`](../reference/test_orcid_match.html)) * The metadata contains a well formatted additionalInfo ("Notes" on DataStore) section ([`test_notes()`](../reference/test_notes.html)) +* The metadata contains a DataStore Project reference in "projects"([`test_project()`](../reference/test_project.html)) ## Metadata and Data Congruence These functions check to make sure the values and fields in the metadata file accurately corresponds to the data files supplied. These test require the entire data package - both the \*_metadata.xml file and all data files (*.csv) must be present. From 51ea460a7c94c400628a0ee9b46e8c492cf02152 Mon Sep 17 00:00:00 2001 From: Rob Baker Date: Thu, 19 Sep 2024 09:41:56 -0600 Subject: [PATCH 07/12] update documentation --- vignettes/DPchecker.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vignettes/DPchecker.Rmd b/vignettes/DPchecker.Rmd index 88c1994..f8406b3 100644 --- a/vignettes/DPchecker.Rmd +++ b/vignettes/DPchecker.Rmd @@ -73,7 +73,7 @@ Warnings are helpful indications that the data package creator may want to look # Tests conducted -DPchecker v0.3.2 runs two types of tests: metadata only tests and tests to determine whether the metadata and data files are congruent. Metadata tests can be broken down in to two sub-categories, metadata compliance and metadata completeness. The tests run and the order in which they are run are listed below. +DPchecker v0.3.2 and above runs two types of tests: metadata only tests and tests to determine whether the metadata and data files are congruent. Metadata tests can be broken down in to two sub-categories, metadata compliance and metadata completeness. The tests run and the order in which they are run are listed below. ## Metadata compliance These tests determine whether the metadata is schema valid and adheres to some rules for data packages. They only require the *_metadata.xml file to run and do not require that the data files be present. These include: From 0be375db7228830f8404fb6d437c6cb880808725 Mon Sep 17 00:00:00 2001 From: Rob Baker Date: Thu, 19 Sep 2024 13:18:33 -0600 Subject: [PATCH 08/12] update news to include set_project tests --- NEWS.md | 5 +++++ 1 file changed, 5 insertions(+) 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 From 3a0fa557e15da1c3d2b685f734b604ec3ec649fa Mon Sep 17 00:00:00 2001 From: Rob Baker Date: Thu, 19 Sep 2024 13:18:53 -0600 Subject: [PATCH 09/12] fix typo in set_data_urls error message --- R/tabular_data_congruence.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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)) From d07fa53647643db069ae05f650d1daaa0c612273 Mon Sep 17 00:00:00 2001 From: Rob Baker Date: Thu, 19 Sep 2024 13:19:14 -0600 Subject: [PATCH 10/12] updated via pkgdown --- docs/404.html | 53 +- docs/LICENSE-text.html | 47 +- docs/LICENSE.html | 49 +- docs/articles/DPchecker.html | 74 +- docs/articles/index.html | 45 +- docs/authors.html | 62 +- docs/deps/bootstrap-5.3.1/bootstrap.min.css | 2 +- .../bootstrap-toc-1.0.1/bootstrap-toc.min.js | 5 + .../deps/clipboard.js-2.0.11/clipboard.min.js | 7 + docs/deps/data-deps.txt | 9 + docs/deps/font-awesome-6.4.2/css/all.css | 7968 +++++++++++++++++ docs/deps/font-awesome-6.4.2/css/all.min.css | 9 + docs/deps/font-awesome-6.4.2/css/v4-shims.css | 2194 +++++ .../font-awesome-6.4.2/css/v4-shims.min.css | 6 + .../webfonts/fa-brands-400.ttf | Bin 0 -> 189684 bytes .../webfonts/fa-brands-400.woff2 | Bin 0 -> 109808 bytes .../webfonts/fa-regular-400.ttf | Bin 0 -> 63348 bytes .../webfonts/fa-regular-400.woff2 | Bin 0 -> 24488 bytes .../webfonts/fa-solid-900.ttf | Bin 0 -> 394668 bytes .../webfonts/fa-solid-900.woff2 | Bin 0 -> 150020 bytes .../webfonts/fa-v4compatibility.ttf | Bin 0 -> 10172 bytes .../webfonts/fa-v4compatibility.woff2 | Bin 0 -> 4568 bytes docs/deps/headroom-0.11.0/headroom.min.js | 7 + .../headroom-0.11.0/jQuery.headroom.min.js | 7 + .../search-1.0.0/autocomplete.jquery.min.js | 7 + docs/deps/search-1.0.0/fuse.min.js | 9 + docs/deps/search-1.0.0/mark.min.js | 7 + docs/index.html | 50 +- docs/katex-auto.js | 14 + docs/lightswitch.js | 85 + docs/news/index.html | 55 +- docs/pkgdown.js | 2 - docs/pkgdown.yml | 5 +- docs/reference/DPchecker-package.html | 49 +- docs/reference/DPchecker_example.html | 57 +- docs/reference/index.html | 309 +- docs/reference/is_eml.html | 53 +- docs/reference/load_data.html | 57 +- docs/reference/load_metadata.html | 59 +- docs/reference/pipe.html | 59 +- docs/reference/reexports.html | 51 +- docs/reference/run_congruence_checks.html | 67 +- docs/reference/test_attribute_defs.html | 63 +- docs/reference/test_by_for_nps.html | 63 +- docs/reference/test_creator.html | 61 +- docs/reference/test_cui_dissemination.html | 63 +- docs/reference/test_datatable_urls.html | 61 +- docs/reference/test_datatable_urls_doi.html | 61 +- docs/reference/test_date_range.html | 61 +- docs/reference/test_dates_parse.html | 61 +- docs/reference/test_delimiter.html | 57 +- docs/reference/test_doi.html | 57 +- docs/reference/test_doi_format.html | 61 +- docs/reference/test_dp_abstract.html | 63 +- docs/reference/test_dp_title.html | 63 +- docs/reference/test_dup_meta_entries.html | 57 +- docs/reference/test_fields_match.html | 59 +- docs/reference/test_file_descript.html | 63 +- docs/reference/test_file_name_match.html | 59 +- docs/reference/test_footer.html | 57 +- docs/reference/test_geographic_cov.html | 57 +- docs/reference/test_header_num.html | 57 +- docs/reference/test_int_rights.html | 63 +- docs/reference/test_keywords.html | 61 +- docs/reference/test_license.html | 63 +- docs/reference/test_metadata_version.html | 57 +- docs/reference/test_methods.html | 61 +- docs/reference/test_missing_data.html | 69 +- docs/reference/test_notes.html | 61 +- docs/reference/test_numeric_fields.html | 59 +- docs/reference/test_orcid_exists.html | 63 +- docs/reference/test_orcid_format.html | 63 +- docs/reference/test_orcid_match.html | 63 +- docs/reference/test_orcid_resolves.html | 63 +- docs/reference/test_pii_data_emails.html | 61 +- docs/reference/test_pii_meta_emails.html | 61 +- docs/reference/test_pub_date.html | 63 +- docs/reference/test_public_points.html | 61 +- docs/reference/test_publisher.html | 59 +- docs/reference/test_publisher_city.html | 63 +- docs/reference/test_publisher_name.html | 63 +- docs/reference/test_publisher_state.html | 63 +- docs/reference/test_storage_type.html | 67 +- docs/reference/test_taxonomic_cov.html | 57 +- docs/reference/test_valid_fieldnames.html | 57 +- docs/reference/test_valid_filenames.html | 57 +- docs/reference/test_validate_schema.html | 57 +- docs/search.json | 2 +- docs/sitemap.xml | 252 +- 89 files changed, 12101 insertions(+), 2431 deletions(-) create mode 100644 docs/deps/bootstrap-toc-1.0.1/bootstrap-toc.min.js create mode 100644 docs/deps/clipboard.js-2.0.11/clipboard.min.js create mode 100644 docs/deps/font-awesome-6.4.2/css/all.css create mode 100644 docs/deps/font-awesome-6.4.2/css/all.min.css create mode 100644 docs/deps/font-awesome-6.4.2/css/v4-shims.css create mode 100644 docs/deps/font-awesome-6.4.2/css/v4-shims.min.css create mode 100644 docs/deps/font-awesome-6.4.2/webfonts/fa-brands-400.ttf create mode 100644 docs/deps/font-awesome-6.4.2/webfonts/fa-brands-400.woff2 create mode 100644 docs/deps/font-awesome-6.4.2/webfonts/fa-regular-400.ttf create mode 100644 docs/deps/font-awesome-6.4.2/webfonts/fa-regular-400.woff2 create mode 100644 docs/deps/font-awesome-6.4.2/webfonts/fa-solid-900.ttf create mode 100644 docs/deps/font-awesome-6.4.2/webfonts/fa-solid-900.woff2 create mode 100644 docs/deps/font-awesome-6.4.2/webfonts/fa-v4compatibility.ttf create mode 100644 docs/deps/font-awesome-6.4.2/webfonts/fa-v4compatibility.woff2 create mode 100644 docs/deps/headroom-0.11.0/headroom.min.js create mode 100644 docs/deps/headroom-0.11.0/jQuery.headroom.min.js create mode 100644 docs/deps/search-1.0.0/autocomplete.jquery.min.js create mode 100644 docs/deps/search-1.0.0/fuse.min.js create mode 100644 docs/deps/search-1.0.0/mark.min.js create mode 100644 docs/katex-auto.js create mode 100644 docs/lightswitch.js 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 - -