Skip to content

Commit

Permalink
Make columns have true NAs instead of string "NA" (#86)
Browse files Browse the repository at this point in the history
- Closes #31
  • Loading branch information
yangsophieee authored Oct 11, 2023
1 parent e4c01ff commit 2ac30e0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 90 deletions.
28 changes: 20 additions & 8 deletions R/process.R
Original file line number Diff line number Diff line change
Expand Up @@ -1601,15 +1601,27 @@ process_format_methods <- function(metadata, dataset_id, sources, contributors)
dataset_id = dataset_id,
source_primary_key = source_primary_key,
source_primary_citation = bib_print(sources[[source_primary_key]]),
source_secondary_key = source_secondary_keys %>% paste(collapse = "; "),
source_secondary_citation = ifelse(length(source_secondary_keys) == 0, NA_character_,
purrr::map_chr(source_secondary_keys, ~sources[[.x]] %>% bib_print) %>% paste(collapse = "; ") %>%
source_secondary_key = ifelse(
length(source_secondary_keys) > 0,
source_secondary_keys %>% paste(collapse = "; "),
NA_character_
),
source_secondary_citation = ifelse(
length(source_secondary_keys) == 0, NA_character_,
purrr::map_chr(source_secondary_keys, ~sources[[.x]] %>% bib_print) %>%
paste(collapse = "; ") %>%
stringr::str_replace_all("\\.;", ";")
),
source_original_dataset_key = ifelse(
length(source_original_dataset_keys) > 0,
source_original_dataset_keys %>% paste(collapse = "; "),
NA_character_
),
source_original_dataset_citation = ifelse(
length(source_original_dataset_keys) == 0, NA_character_,
purrr::map_chr(source_original_dataset_keys, ~sources[[.x]] %>% bib_print) %>%
paste(collapse = "; ") %>%
stringr::str_replace_all("\\.;", ";")
),
source_original_dataset_key = source_original_dataset_keys %>% paste(collapse = "; "),
source_original_dataset_citation = ifelse(length(source_original_dataset_keys) == 0, NA_character_,
purrr::map_chr(source_original_dataset_keys, ~sources[[.x]] %>% bib_print) %>% paste(collapse = "; ") %>%
stringr::str_replace_all("\\.;", ";")
)
)
) %>%
Expand Down
82 changes: 0 additions & 82 deletions tests/testthat/test-xamples.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,6 @@ testthat::test_that("Test Dataset 1 builds correctly", {
# Todo: also load and test non-csv outputs
names(expected_output) <- tables

# Temporary modifications to get these tests to pass
Test_2023_1$traits <-
Test_2023_1$traits %>%
mutate(across(
c(temporal_context_id, entity_context_id, plot_context_id, treatment_context_id, method_context_id),
~if_else(.x == "NA", NA_character_, .x)
))
Test_2023_1$methods <-
Test_2023_1$methods %>%
mutate(across(c(source_secondary_key, source_original_dataset_key), ~NA_character_))
Test_2023_1$excluded_data <-
Test_2023_1$excluded_data %>%
mutate(across(
c(temporal_context_id, entity_context_id, plot_context_id, treatment_context_id, method_context_id),
~if_else(.x == "NA", NA_character_, .x)
))

# Check all tables are equal to expected output tables
for (v in tables) {
expect_equal(Test_2023_1[[v]], expected_output[[v]])
Expand Down Expand Up @@ -86,19 +69,6 @@ testthat::test_that("Test Dataset 2 builds correctly", {
# Todo: also load and test non-csv outputs
names(expected_output) <- tables

# Temporary modifications to get these tests to pass
columns <- c("basis_of_value", "replicates", "life_stage", "collection_date", "measurement_remarks")

Test_2023_2$traits <-
Test_2023_2$traits %>%
mutate(across(dplyr::all_of(columns), as.character))
Test_2023_2$methods <-
Test_2023_2$methods %>%
mutate(across(c(source_secondary_key, source_original_dataset_key), ~NA_character_))
Test_2023_2$excluded_data <-
Test_2023_2$excluded_data %>%
mutate(across(dplyr::all_of(columns), as.character))

# Check all tables are equal to expected output tables
for (v in tables) {
expect_equal(Test_2023_2[[v]], expected_output[[v]])
Expand Down Expand Up @@ -133,19 +103,6 @@ testthat::test_that("Test Dataset 3 builds correctly", {
# Todo: also load and test non-csv outputs
names(expected_output) <- tables

# Temporary modifications to get these tests to pass
columns <- c("basis_of_value", "replicates", "life_stage", "collection_date", "measurement_remarks")

Test_2023_3$traits <-
Test_2023_3$traits %>%
mutate(across(dplyr::all_of(columns), as.character))
Test_2023_3$methods <-
Test_2023_3$methods %>%
mutate(across(c(source_secondary_key, source_original_dataset_key), ~NA_character_))
Test_2023_3$excluded_data <-
Test_2023_3$excluded_data %>%
mutate(across(dplyr::all_of(columns), as.character))

# Check all tables are equal to expected output tables
for (v in tables) {
expect_equal(Test_2023_3[[v]], expected_output[[v]])
Expand Down Expand Up @@ -180,19 +137,6 @@ testthat::test_that("Test Dataset 4 builds correctly", {
# Todo: also load and test non-csv outputs
names(expected_output) <- tables

# Temporary modifications to get these tests to pass
columns <- c("basis_of_value", "replicates", "life_stage", "collection_date", "measurement_remarks")

Test_2023_4$traits <-
Test_2023_4$traits %>%
mutate(across(dplyr::all_of(columns), as.character))
Test_2023_4$methods <-
Test_2023_4$methods %>%
mutate(across(c(source_secondary_key, source_original_dataset_key), ~NA_character_))
Test_2023_4$excluded_data <-
Test_2023_4$excluded_data %>%
mutate(across(dplyr::all_of(columns), as.character))

# Check all tables are equal to expected output tables
for (v in tables) {
expect_equal(Test_2023_4[[v]], expected_output[[v]])
Expand Down Expand Up @@ -255,19 +199,6 @@ testthat::test_that("Test Dataset 7 builds correctly", {
# Todo: also load and test non-csv outputs
names(expected_output) <- tables

# Temporary modifications to get these tests to pass
columns <- c("basis_of_value", "replicates", "life_stage", "collection_date", "measurement_remarks")

Test_2023_7$traits <-
Test_2023_7$traits %>%
mutate(across(dplyr::all_of(columns), as.character))
Test_2023_7$methods <-
Test_2023_7$methods %>%
mutate(across(c(source_secondary_key, source_original_dataset_key), ~NA_character_))
Test_2023_7$excluded_data <-
Test_2023_7$excluded_data %>%
mutate(across(dplyr::all_of(columns), as.character))

# Check all tables are equal to expected output tables
for (v in tables) {
expect_equal(Test_2023_7[[v]], expected_output[[v]])
Expand Down Expand Up @@ -302,19 +233,6 @@ testthat::test_that("Test Dataset 8 builds correctly", {
# Todo: also load and test non-csv outputs
names(expected_output) <- tables

# Temporary modifications to get these tests to pass
columns <- c("basis_of_value", "replicates", "life_stage", "collection_date", "measurement_remarks")

Test_2023_8$traits <-
Test_2023_8$traits %>%
mutate(across(dplyr::all_of(columns), as.character))
Test_2023_8$methods <-
Test_2023_8$methods %>%
mutate(across(c(source_secondary_key, source_original_dataset_key), ~NA_character_))
Test_2023_8$excluded_data <-
Test_2023_8$excluded_data %>%
mutate(across(dplyr::all_of(columns), as.character))

# Check all tables are equal to expected output tables
for (v in tables) {
expect_equal(Test_2023_8[[v]], expected_output[[v]])
Expand Down

0 comments on commit 2ac30e0

Please sign in to comment.