From 947ad015e40b147459d48de62dd5eb2eb5740a2d Mon Sep 17 00:00:00 2001 From: Sharla Gelfand Date: Wed, 28 Jul 2021 14:45:05 -0400 Subject: [PATCH] R cmd check --- DESCRIPTION | 8 ++--- R/prep_specs_summarize.R | 2 +- tests/testthat/helper.R | 4 +-- tests/testthat/test-prep_specs_summarize.R | 39 +++++++++++++--------- 4 files changed, 30 insertions(+), 23 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 4387e674..a86e992a 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: datamations Type: Package Title: Animated Explanations of Data Analysis Pipelines -Version: 0.0.0.9008 +Version: 0.0.0.9009 Authors@R: c( person("Xiaoying", "Pu", email = "xpu@umich.edu", role = c("aut")), person("Sean", "Kross", email = "smk240@gmail.com", role = c("aut")), @@ -35,13 +35,11 @@ Imports: shinyWidgets, shinydashboard, shinyAce, + jsonlite, + palmerpenguins, golem, styler, shinyjs Suggests: - jsonlite, - palmerpenguins, testthat (>= 2.1.0) -Depends: - R (>= 3.5.0) Config/testthat/edition: 3 diff --git a/R/prep_specs_summarize.R b/R/prep_specs_summarize.R index 11f73532..341dcb56 100644 --- a/R/prep_specs_summarize.R +++ b/R/prep_specs_summarize.R @@ -211,7 +211,7 @@ prep_specs_summarize <- function(.data, mapping, toJSON = TRUE, pretty = TRUE, h sign = ifelse(.x == "Upper", "+", "-") ))) tooltip_encoding_first <- list(spec_encoding$tooltip[[1]]) - tooltip_encoding_rest <- list(spec_encoding$tooltip[[-1]]) + tooltip_encoding_rest <- list(spec_encoding$tooltip[-1]) errorbar_tooltip <- append(tooltip_encoding_first, errorbar_tooltip) errorbar_tooltip <- append(errorbar_tooltip, tooltip_encoding_rest) diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index de5dc1ab..f93de5a5 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -30,9 +30,9 @@ expect_data_values <- function(single_spec, df) { dplyr::mutate_if(is.factor, as.character) %>% dplyr::mutate_if(is.character, dplyr::coalesce, "NA") - if ("y" %in% names(df)) { + if (Y_FIELD_CHR %in% names(df)) { df <- df %>% - dplyr::filter(!is.na(y)) + dplyr::filter(!is.na(!!Y_FIELD)) } spec_data <- single_spec %>% diff --git a/tests/testthat/test-prep_specs_summarize.R b/tests/testthat/test-prep_specs_summarize.R index d502a71d..45353edb 100644 --- a/tests/testthat/test-prep_specs_summarize.R +++ b/tests/testthat/test-prep_specs_summarize.R @@ -12,15 +12,18 @@ test_that("prep_specs_summarize returns a list with four elements - one for the expect_meta_axes(specs, TRUE) # Axes are set to TRUE to be shown expect_data_values(specs[[1]], palmerpenguins::penguins %>% dplyr::arrange(species) %>% - dplyr::mutate(x = 1, gemini_id = dplyr::row_number()) %>% - dplyr::select(gemini_id, species, x, y = bill_length_mm)) # One data value for each row in the input data frame, containing grouping variables - x value depending on the grouping - x = 1 if n_groups != 3 + dplyr::mutate(!!X_FIELD := 1, gemini_id = dplyr::row_number()) %>% + dplyr::select(gemini_id, species, !!X_FIELD, !!Y_FIELD := bill_length_mm, !!Y_TOOLTIP_FIELD := bill_length_mm)) # One data value for each row in the input data frame, containing grouping variables - x value depending on the grouping - x = 1 if n_groups != 3 expect_data_values(specs[[2]], palmerpenguins::penguins %>% dplyr::arrange(species) %>% - dplyr::mutate(x = 1, gemini_id = dplyr::row_number()) %>% + dplyr::mutate(!!X_FIELD := 1, gemini_id = dplyr::row_number()) %>% dplyr::filter(!is.na(bill_length_mm)) %>% dplyr::group_by(species) %>% - dplyr::mutate(y = mean(bill_length_mm, na.rm = TRUE)) %>% - dplyr::select(gemini_id, species, x, y) %>% + dplyr::mutate( + !!Y_FIELD := mean(bill_length_mm, na.rm = TRUE), + !!Y_TOOLTIP_FIELD := !!Y_FIELD + ) %>% + dplyr::select(gemini_id, species, !!X_FIELD, !!Y_FIELD, !!Y_TOOLTIP_FIELD) %>% dplyr::ungroup()) # Second element, all of the values are the summary value expect_spec_contains_mark_encoding(specs[1:2]) # mark and encoding are within `spec` for the first two specs - it works differently for the error bars, since they are layered expect_grouping_order_1(specs[[1]]) # The grouping order is correct @@ -41,20 +44,23 @@ test_that("prep_specs_summarize returns a list with four elements - one for the dplyr::arrange(species, island, sex) %>% dplyr::mutate( gemini_id = dplyr::row_number(), - x = 1, + !!X_FIELD := 1, ) %>% dplyr::filter(!is.na(bill_length_mm)) %>% - dplyr::select(gemini_id, species, island, sex, x, y = bill_length_mm)) # One data value for each row in the input data frame, containing grouping variables - x value depending on the grouping - x = 1 if n_groups != 3 + dplyr::select(gemini_id, species, island, sex, !!X_FIELD, !!Y_FIELD := bill_length_mm, !!Y_TOOLTIP_FIELD := bill_length_mm)) # One data value for each row in the input data frame, containing grouping variables - x value depending on the grouping - x = 1 if n_groups != 3 expect_data_values(specs[[2]], palmerpenguins::penguins %>% dplyr::arrange(species, island, sex) %>% dplyr::mutate( gemini_id = dplyr::row_number(), - x = 1 + !!X_FIELD := 1 ) %>% dplyr::filter(!is.na(bill_length_mm)) %>% dplyr::group_by(species, island, sex) %>% - dplyr::mutate(y = mean(bill_length_mm, na.rm = TRUE)) %>% - dplyr::select(gemini_id, species, island, sex, x, y) %>% + dplyr::mutate( + !!Y_FIELD := mean(bill_length_mm, na.rm = TRUE), + !!Y_TOOLTIP_FIELD := !!Y_FIELD + ) %>% + dplyr::select(gemini_id, species, island, sex, !!X_FIELD, !!Y_FIELD, !!Y_TOOLTIP_FIELD) %>% dplyr::ungroup()) # Second element, all of the values are the summary value expect_spec_contains_mark_encoding(specs[1:2]) # mark and encoding are within `spec` expect_grouping_order_3(specs[[1]]) # The grouping order is correct @@ -73,13 +79,16 @@ test_that("prep_specs_summarize returns a list with four elements - one for the expect_meta_parse_value(specs[2], NULL) # Second element meta is empty expect_meta_axes(specs, FALSE) # Additional axes are NOT shown when there's no groups expect_data_values(specs[[1]], palmerpenguins::penguins %>% - dplyr::mutate(x = 1, gemini_id = dplyr::row_number()) %>% - dplyr::select(gemini_id, x, y = bill_length_mm)) # One data value for each row in the input data frame, containing grouping variables - x value depending on the grouping - x = 1 if n_groups != 3 + dplyr::mutate(!!X_FIELD := 1, gemini_id = dplyr::row_number()) %>% + dplyr::select(gemini_id, !!X_FIELD, !!Y_FIELD := bill_length_mm, !!Y_TOOLTIP_FIELD := bill_length_mm)) # One data value for each row in the input data frame, containing grouping variables - x value depending on the grouping - x = 1 if n_groups != 3 expect_data_values(specs[[2]], palmerpenguins::penguins %>% - dplyr::mutate(x = 1, gemini_id = dplyr::row_number()) %>% + dplyr::mutate(!!X_FIELD := 1, gemini_id = dplyr::row_number()) %>% dplyr::filter(!is.na(bill_length_mm)) %>% - dplyr::mutate(y = mean(bill_length_mm, na.rm = TRUE)) %>% - dplyr::select(gemini_id, x, y)) + dplyr::mutate( + !!Y_FIELD := mean(bill_length_mm, na.rm = TRUE), + !!Y_TOOLTIP_FIELD := !!Y_FIELD + ) %>% + dplyr::select(gemini_id, !!X_FIELD, !!Y_FIELD, !!Y_TOOLTIP_FIELD)) expect_mark_encoding_top_level(specs[1:2]) # mark and encoding are at the top level expect_no_grouping(specs) # There is no grouping })