Skip to content

Commit b3b2cf0

Browse files
committed
refactor multiple functions for better edge case handling
1 parent 8115a1d commit b3b2cf0

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

R/tabular_data_congruence.R

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ test_file_name_match <- function(directory = here::here(), metadata = load_metad
488488
if (length(meta_only) == 0 && length(dir_only) == 0) {
489489
cli::cli_inform(c("v" = "All data files are listed in metadata and all metadata files names refer to data files."))
490490
} else if (length(meta_only) > 0 || length(dir_only) > 0) {
491-
msg <- c()
491+
msg <- NULL
492492
if (length(meta_only > 0)) {
493493
names(meta_only) <- rep("*", length(meta_only))
494494
msg <- c("x" = "{length(meta_only)} file{?s} listed in metadata but missing from data folder", meta_only)
@@ -536,7 +536,7 @@ test_fields_match <- function(directory = here::here(), metadata = load_metadata
536536

537537
#get names of each file to add to attributes table
538538
table_names <- NULL
539-
for (i in 1:length(seq_along(data_files))) {
539+
for (i in seq_along(data_files)) {
540540
tbl_nam <- data_tbl[[i]][["physical"]][["objectName"]]
541541
table_names <- append(table_names, tbl_nam)
542542
}
@@ -625,14 +625,14 @@ test_missing_data <- function(directory = here::here(),
625625

626626
#load files and test for NAs
627627
error_log <- NULL
628-
for (i in 1:length(seq_along(data_files))) {
628+
for (i in seq_along(data_files)) {
629629
#load each file
630630
dat <- suppressMessages(readr::read_csv(paste0(directory,
631631
"/",
632632
data_files[i]),
633633
show_col_types = FALSE))
634634
#look in each column in the given file
635-
for (j in 1:ncol(dat)) {
635+
for (j in seq_len(ncol(dat))) {
636636
#look for NAs; if NAs found, look for correct missing data codes
637637
if (sum(is.na(dat[,j])) > 0) {
638638
missing <- data_tbl[[i]][["attributeList"]][["attribute"]][[j]][["missingValueCode"]][["code"]]
@@ -702,7 +702,7 @@ test_numeric_fields <- function(directory = here::here(), metadata = load_metada
702702

703703
#get names of each file to add to attributes table
704704
table_names <- NULL
705-
for (i in 1:length(seq_along(data_files))) {
705+
for (i in seq_along(data_files)) {
706706
tbl_nam <- data_tbl[[i]][["physical"]][["objectName"]]
707707
table_names <- append(table_names, tbl_nam)
708708
}
@@ -818,7 +818,7 @@ test_dates_parse <- function(directory = here::here(),
818818

819819
#get names of each file to add to dttm attributes table
820820
table_names <- NULL
821-
for (i in 1:length(seq_along(data_tbl))) {
821+
for (i in seq_along(data_tbl)) {
822822
tbl_nam <- data_tbl[[i]][["physical"]][["objectName"]]
823823
table_names <- append(table_names, tbl_nam)
824824
}
@@ -1014,7 +1014,7 @@ test_date_range <- function(directory = here::here(),
10141014

10151015
#get names of each file to add to dttm attributes table
10161016
table_names <- NULL
1017-
for (i in 1:length(seq_along(data_tbl))) {
1017+
for (i in seq_along(data_tbl)) {
10181018
tbl_nam <- data_tbl[[i]][["physical"]][["objectName"]]
10191019
table_names <- append(table_names, tbl_nam)
10201020
}
@@ -1340,7 +1340,7 @@ test_valid_fieldnames <- function(metadata = load_metadata(here::here())) {
13401340

13411341
#get names of each file to add to attributes table
13421342
table_names <- NULL
1343-
for (i in 1:length(seq_along(data_tbl))) {
1343+
for (i in seq_along(data_tbl)) {
13441344
tbl_nam <- data_tbl[[i]][["physical"]][["objectName"]]
13451345
table_names <- append(table_names, tbl_nam)
13461346
}
@@ -1403,7 +1403,7 @@ test_valid_filenames <- function(metadata = load_metadata(here::here())) {
14031403

14041404
#get names of each file to add to attributes table
14051405
file_names <- NULL
1406-
for (i in 1:length(seq_along(data_tbl))) {
1406+
for (i in seq_along(data_tbl)) {
14071407
tbl_nam <- data_tbl[[i]][["physical"]][["objectName"]]
14081408
file_names <- append(file_names, tbl_nam)
14091409
}

0 commit comments

Comments
 (0)