Skip to content

Commit

Permalink
Fix metadata_add_location (#40)
Browse files Browse the repository at this point in the history
Issue probably arose from adding in `tidyselect` terms `all_of` and `any_of` a while back. I'm assuming that during this process, the first argument of select (.data) was erroneously put into an `all_of` argument. Dan also simplified some lines.
- Closes #39

---------

Co-authored-by: Daniel Falster <[email protected]>
  • Loading branch information
yangsophieee and dfalster authored Aug 9, 2023
1 parent 9ca56af commit 1222fb6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 13 additions & 7 deletions R/setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -254,27 +254,33 @@ metadata_add_traits <- function(dataset_id) {
#' }
metadata_add_locations <- function(dataset_id, location_data) {

vars <- names(location_data)

# read metadata
metadata <- read_metadata_dataset(dataset_id)

# Choose column for location_name
location_name <- metadata_user_select_column("location_name", names(location_data))
location_name <- metadata_user_select_column("location_name", vars)

# From remaining variables, choose those to keep
location_sub <- dplyr::select(dplyr::all_of(c("location_data"), -!!location_name))
keep <- metadata_user_select_names(
paste("Indicate all columns you wish to keep as distinct location_properties in ",
dataset_id), names(location_sub)
dataset_id), vars[vars != location_name]
)

# Save and notify
metadata$locations <- dplyr::select(dplyr::all_of(c("location_data"), tidyr::one_of(keep))) %>%
split(location_data[[location_name]]) %>% lapply(as.list)
metadata$locations <- location_data %>%
dplyr::select(dplyr::all_of(keep)) %>%
split(location_data[[location_name]]) %>%
lapply(as.list)

cat(
sprintf("Following locations added to metadata for %s: %s\n\twith variables %s.\n\tPlease complete information in %s.\n\n",
dataset_id, crayon::red(paste(names(metadata$locations), collapse = ", ")),
crayon::red(paste(keep, collapse = ", ")), dataset_id %>% metadata_path_dataset_id())
dataset_id,
crayon::red(paste(names(metadata$locations), collapse = ", ")),
crayon::red(paste(keep, collapse = ", ")),
dataset_id %>% metadata_path_dataset_id()
)
)

write_metadata_dataset(metadata, dataset_id)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ test_that("reports and plots are produced", {
)
})

testthat::test_that("test_data is working", {
testthat::test_that("dataset_test is working", {
expect_silent(
out <- dataset_test("Test_2022", reporter = testthat::SilentReporter))
expect_in(
Expand Down

0 comments on commit 1222fb6

Please sign in to comment.