Skip to content

Commit 8115a1d

Browse files
authored
Merge pull request nationalparkservice#125 from RobLBaker/main
bug fixes for multiple functions using arcticdatautils::eml_get_simple
2 parents 4e2be28 + f8fa2ac commit 8115a1d

11 files changed

+200
-31
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# DPchecker development version
22

3+
* Bugfixes for `test_valid_fieldnames()`, `test_valid_filenames()`, `test_numeric_fields()`, `test_dates_parse()`, and `test_date_range()` - all the same bug; must be something deep in a dependency chain changed.
34
* Bugfix attempt for `test_fields_match()` reportedly needs more testing
45
* Add function `test_missing_data()` which scans data for NAs not documented in metadata
56

R/tabular_data_congruence.R

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -696,11 +696,19 @@ test_numeric_fields <- function(directory = here::here(), metadata = load_metada
696696
return(attrs)
697697
})
698698
numeric_attrs$`@context` <- NULL
699-
names(numeric_attrs) <- arcticdatautils::eml_get_simple(data_tbl, "objectName")
700699

701700
# Get list of column names for each table in the csv data
702701
data_files <- list.files(path = directory, pattern = ".csv")
703702

703+
#get names of each file to add to attributes table
704+
table_names <- NULL
705+
for (i in 1:length(seq_along(data_files))) {
706+
tbl_nam <- data_tbl[[i]][["physical"]][["objectName"]]
707+
table_names <- append(table_names, tbl_nam)
708+
}
709+
#list nmeric attributes by file name
710+
names(numeric_attrs) <- table_names
711+
704712
data_non_numeric <- sapply(data_files, function(data_file) {
705713
num_col_names <- numeric_attrs[[data_file]]$attributeName
706714

@@ -805,14 +813,21 @@ test_dates_parse <- function(directory = here::here(),
805813
})
806814
dttm_attrs$`@context` <- NULL
807815

808-
names(dttm_attrs) <- arcticdatautils::eml_get_simple(data_tbl, "objectName")
809-
810-
# For each csv table, check that date/time columns are consistent with temporal coverage in metadata. List out tables and columns that are not in compliance.
816+
#get list of file names
811817
data_files <- list.files(path = directory, pattern = ".csv")
812818

819+
#get names of each file to add to dttm attributes table
820+
table_names <- NULL
821+
for (i in 1:length(seq_along(data_tbl))) {
822+
tbl_nam <- data_tbl[[i]][["physical"]][["objectName"]]
823+
table_names <- append(table_names, tbl_nam)
824+
}
825+
#list metadata attributes by file name
826+
names(dttm_attrs) <- table_names
827+
828+
# For each csv table, check that date/time columns are consistent with temporal coverage in metadata. List out tables and columns that are not in compliance.
813829
#log errors. Assume none until one is found.
814830
error_log <- NULL
815-
816831
for(i in seq_along(data_files)){
817832
data_file <- data_tbl[[i]][["physical"]][["objectName"]]
818833

@@ -994,10 +1009,19 @@ test_date_range <- function(directory = here::here(),
9941009
}
9951010
}
9961011

997-
names(dttm_attrs) <- arcticdatautils::eml_get_simple(data_tbl, "objectName")
1012+
#get list of file names
1013+
data_files <- list.files(path = directory, pattern = ".csv")
1014+
1015+
#get names of each file to add to dttm attributes table
1016+
table_names <- NULL
1017+
for (i in 1:length(seq_along(data_tbl))) {
1018+
tbl_nam <- data_tbl[[i]][["physical"]][["objectName"]]
1019+
table_names <- append(table_names, tbl_nam)
1020+
}
1021+
#list metadata attributes by file name
1022+
names(dttm_attrs) <- table_names
9981023

9991024
# For each csv table, check that date/time columns are consistent with temporal coverage in metadata. List out tables and columns that are not in compliance.
1000-
data_files <- list.files(path = directory, pattern = ".csv")
10011025
dataset_out_of_range <- sapply(data_files, function(data_file) {
10021026
dttm_col_names <- dttm_attrs[[data_file]]$attributeName
10031027
# If the table doesn't have any date/time columns listed in the metadata, it automatically passes
@@ -1313,7 +1337,15 @@ test_valid_fieldnames <- function(metadata = load_metadata(here::here())) {
13131337
# Get list of columns for each table in the metadata
13141338
metadata_attrs <- lapply(data_tbl, function(tbl) {arcticdatautils::eml_get_simple(tbl, "attributeName")})
13151339
metadata_attrs$`@context` <- NULL
1316-
names(metadata_attrs) <- arcticdatautils::eml_get_simple(data_tbl, "objectName")
1340+
1341+
#get names of each file to add to attributes table
1342+
table_names <- NULL
1343+
for (i in 1:length(seq_along(data_tbl))) {
1344+
tbl_nam <- data_tbl[[i]][["physical"]][["objectName"]]
1345+
table_names <- append(table_names, tbl_nam)
1346+
}
1347+
#list metadata attributes by file name
1348+
names(metadata_attrs) <- table_names
13171349

13181350
# Check each table. Throw a warning if they contain special characters
13191351
bad_fieldnames <- sapply(names(metadata_attrs), function(tbl) {
@@ -1369,8 +1401,12 @@ test_valid_filenames <- function(metadata = load_metadata(here::here())) {
13691401
data_tbl <- list(data_tbl)
13701402
}
13711403

1372-
# Get vector of filenames from the metadata
1373-
file_names <- arcticdatautils::eml_get_simple(data_tbl, "objectName")
1404+
#get names of each file to add to attributes table
1405+
file_names <- NULL
1406+
for (i in 1:length(seq_along(data_tbl))) {
1407+
tbl_nam <- data_tbl[[i]][["physical"]][["objectName"]]
1408+
file_names <- append(file_names, tbl_nam)
1409+
}
13741410

13751411
# Check each file name. Throw a warning if any contain special characters
13761412
bad_start <- grepl("^[^a-zA-Z]", file_names) # File names must start with a letter

docs/pkgdown.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ pkgdown: 2.0.7
33
pkgdown_sha: ~
44
articles:
55
DPchecker: DPchecker.html
6-
last_built: 2024-01-11T22:24Z
6+
last_built: 2024-01-16T17:59Z
77

docs/reference/DPchecker_example.html

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/run_congruence_checks.html

Lines changed: 71 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)