From c12d6a4fbda051d23267d1589e5b747b8272a41f Mon Sep 17 00:00:00 2001 From: olivroy Date: Tue, 26 Nov 2024 14:20:38 -0500 Subject: [PATCH] Fix lints Avoid old dplyr verbs Fix rlang 0.3 deprecation warning Remove workaround since pointblank imports gt 0.9.0 Remove partial amatching --- R/col_vals_between.R | 5 ++++ R/col_vals_not_between.R | 6 +++++ R/get_agent_report.R | 4 ++-- R/get_multiagent_report.R | 4 ++-- R/incorporate.R | 7 +++++- R/interrogate.R | 12 +++++----- R/scan_data.R | 6 ++--- R/tbl_from_db.R | 4 ++++ R/utils-profiling.R | 2 +- R/utils.R | 11 ++++----- tests/testthat/test-get_informant_report.R | 4 ++-- .../test-incorporate_with_informant.R | 23 ++++++++----------- tests/testthat/test-yaml_exec.R | 3 ++- tests/testthat/test-yaml_read_informant.R | 2 +- 14 files changed, 54 insertions(+), 39 deletions(-) diff --git a/R/col_vals_between.R b/R/col_vals_between.R index 24e264ba1..b348fbe4c 100644 --- a/R/col_vals_between.R +++ b/R/col_vals_between.R @@ -428,6 +428,11 @@ col_vals_between <- function( agent <- x + # Avoid rlang (>= 0.3.0) soft deprecation warning + # Quosure lists can't be concatenated with objects other than quosures. + left <- as.list(left) + right <- as.list(right) + if (is.null(brief)) { brief <- diff --git a/R/col_vals_not_between.R b/R/col_vals_not_between.R index 1232882ca..23e5c94f1 100644 --- a/R/col_vals_not_between.R +++ b/R/col_vals_not_between.R @@ -431,6 +431,12 @@ col_vals_not_between <- function( agent <- x + # Avoid rlang (>= 0.3.0) soft deprecation warning + # Quosure lists can't be concatenated with objects other than quosures + + left <- as.list(left) + right <- as.list(right) + if (is.null(brief)) { brief <- diff --git a/R/get_agent_report.R b/R/get_agent_report.R index 06d61511b..021cb09c0 100644 --- a/R/get_agent_report.R +++ b/R/get_agent_report.R @@ -1682,8 +1682,8 @@ get_agent_report <- function( "eval_sym", "W", "S", "N", "extract" ) ) %>% - gt_missing(columns = c("columns", "values", "units", "extract")) %>% - gt_missing(columns = "status_color", missing_text = "") %>% + gt::sub_missing(columns = c("columns", "values", "units", "extract")) %>% + gt::sub_missing(columns = "status_color", missing_text = "") %>% gt::cols_hide(columns = c("W_val", "S_val", "N_val", "active", "eval")) %>% gt::text_transform( locations = gt::cells_body(columns = "units"), diff --git a/R/get_multiagent_report.R b/R/get_multiagent_report.R index 8ed4d28c9..2b2cb7ae4 100644 --- a/R/get_multiagent_report.R +++ b/R/get_multiagent_report.R @@ -809,7 +809,7 @@ get_multiagent_report <- function( ) %>% gt::fmt_markdown(columns = 2:n_columns) %>% gt::fmt_markdown(columns = "sha1") %>% - gt_missing( + gt::sub_missing( columns = columns_used_tbl, missing_text = gt::html( as.character( @@ -824,7 +824,7 @@ get_multiagent_report <- function( ) ) ) %>% - gt_missing( + gt::sub_missing( columns = columns_not_used, missing_text = "" ) %>% diff --git a/R/incorporate.R b/R/incorporate.R index c7346f49e..808bf0240 100644 --- a/R/incorporate.R +++ b/R/incorporate.R @@ -166,7 +166,12 @@ incorporate <- function(informant) { # Get the target table for this informant object # TODO: extend the materialize table function to use an agent or informant - tbl <- informant$tbl + if (rlang::has_name(informant, "tbl")) { + # Avoid partial matching + tbl <- informant$tbl + } else { + tbl <- informant$tbl_name + } tbl_name <- informant$tbl_name read_fn <- informant$read_fn diff --git a/R/interrogate.R b/R/interrogate.R index 3d70c86a4..5ba998047 100644 --- a/R/interrogate.R +++ b/R/interrogate.R @@ -3331,9 +3331,9 @@ add_table_extract <- function( ) { problem_rows <- - dplyr::sample_n( - tbl = problem_rows, - size = sample_n, + dplyr::slice_sample( + problem_rows, + n = sample_n, replace = FALSE) %>% dplyr::as_tibble() @@ -3345,9 +3345,9 @@ add_table_extract <- function( ) { problem_rows <- - dplyr::sample_frac( - tbl = problem_rows, - size = sample_frac, + dplyr::slice_sample( + problem_rows, + prop = sample_frac, replace = FALSE) %>% dplyr::as_tibble() %>% utils::head(sample_limit) diff --git a/R/scan_data.R b/R/scan_data.R index cf1520e17..07380bfd4 100644 --- a/R/scan_data.R +++ b/R/scan_data.R @@ -809,7 +809,7 @@ get_common_values_gt <- function( n = get_lsv("table_scan/tbl_lab_count")[[lang]], frequency = get_lsv("table_scan/tbl_lab_frequency")[[lang]], ) %>% - gt_missing(columns = "value", missing_text = "**NA**") %>% + gt::sub_missing(columns = "value", missing_text = "**NA**") %>% gt::text_transform( locations = gt::cells_body(columns = "value"), fn = function(x) { @@ -847,7 +847,7 @@ get_common_values_gt <- function( n = get_lsv("table_scan/tbl_lab_count")[[lang]], frequency = get_lsv("table_scan/tbl_lab_frequency")[[lang]], ) %>% - gt_missing(columns = "value", missing_text = "**NA**") %>% + gt::sub_missing(columns = "value", missing_text = "**NA**") %>% gt::text_transform( locations = gt::cells_body(columns = "value"), fn = function(x) ifelse(x == "**NA**", "NA", x) @@ -1539,7 +1539,7 @@ probe_sample <- function(data) { probe_sample <- data %>% gt::gt_preview(top_n = 5, bottom_n = 5) %>% - gt_missing(columns = gt::everything(), missing_text = "**NA**") %>% + gt::sub_missing(columns = gt::everything(), missing_text = "**NA**") %>% gt::text_transform( locations = gt::cells_body(columns = gt::everything()), fn = function(x) ifelse(x == "**NA**", "NA", x) diff --git a/R/tbl_from_db.R b/R/tbl_from_db.R index 4dba310b3..12e836074 100644 --- a/R/tbl_from_db.R +++ b/R/tbl_from_db.R @@ -513,6 +513,8 @@ db_tbl <- function( x } +# nolint start + RPostgres_driver <- function() { rlang::check_installed("RPostgres", "to access a PostgreSQL table.") RPostgres::Postgres() @@ -538,6 +540,8 @@ RSQLite_driver <- function() { RSQLite::SQLite() } +# nolint end + unknown_driver <- function() { stop( diff --git a/R/utils-profiling.R b/R/utils-profiling.R index adc88eb00..8ca2d9454 100644 --- a/R/utils-profiling.R +++ b/R/utils-profiling.R @@ -617,7 +617,7 @@ get_table_slice_gt <- function(data_column, data_column %>% gt::gt() %>% gt::fmt_percent(columns = 3, locale = locale) %>% - gt_missing(columns = 1, missing_text = "**NA**") %>% + gt::sub_missing(columns = 1, missing_text = "**NA**") %>% gt::text_transform( locations = gt::cells_body(columns = 1), fn = function(x) ifelse(x == "**NA**", "NA", x) diff --git a/R/utils.R b/R/utils.R index 7a2ec1231..329a8eb99 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1643,13 +1643,6 @@ print_time <- function(time_diff_s) { ) } -gt_missing <- - if (utils::packageVersion("gt") >= "0.6.0") { - gt::sub_missing - } else { - gt::fmt_missing - } - pb_get_image_tag <- function(file, dir = "images") { repo_url <- "https://raw.githubusercontent.com/rstudio/pointblank/main" @@ -1691,6 +1684,10 @@ pb_get_image_tag <- function(file, dir = "images") { deparse_expr <- function(expr, collapse = " ", ...) { if (rlang::is_scalar_atomic(expr)) { as.character(expr) + } else if (rlang::is_quosure(expr)) { + expr <- rlang::quo_get_expr(expr) + deparsed <- paste(deparse(expr, ...), collapse = collapse) + paste("", deparsed) } else { deparsed <- paste(deparse(expr, ...), collapse = collapse) paste("", deparsed) diff --git a/tests/testthat/test-get_informant_report.R b/tests/testthat/test-get_informant_report.R index f920cbfcf..a96624892 100644 --- a/tests/testthat/test-get_informant_report.R +++ b/tests/testthat/test-get_informant_report.R @@ -5,7 +5,7 @@ test_that("Getting an information report is possible", { # `incorporate()` the snippets into the info text informant <- create_informant( - tbl = ~ readr::read_csv(file = "test_table.csv", col_types = "TDdcddlc"), + tbl = ~ readr::read_csv(file = test_path("test_table.csv"), col_types = "TDdcddlc"), tbl_name = "test_table", label = "An example." ) %>% @@ -54,7 +54,7 @@ test_that("Getting a more advanced information report is possible", { informant <- create_informant( - tbl = ~ readr::read_csv(file = "penguins.csv", col_types = "ccddddcd"), + tbl = ~ readr::read_csv(file = test_path("penguins.csv"), col_types = "ccddddcd"), tbl_name = "penguins", label = "The `penguins` dataset from the **palmerpenguins** 📦." ) %>% diff --git a/tests/testthat/test-incorporate_with_informant.R b/tests/testthat/test-incorporate_with_informant.R index f13079531..663af0361 100644 --- a/tests/testthat/test-incorporate_with_informant.R +++ b/tests/testthat/test-incorporate_with_informant.R @@ -5,7 +5,7 @@ test_that("Incorporating an informant yields the correct results", { # `incorporate()` the snippets into the info text informant <- create_informant( - tbl = ~ readr::read_csv(file = "test_table.csv", col_types = "TDdcddlc"), + tbl = ~ readr::read_csv(file = testthat::test_path("test_table.csv"), col_types = "TDdcddlc"), tbl_name = "test_table", label = "An example." ) %>% @@ -41,14 +41,11 @@ test_that("Incorporating an informant yields the correct results", { # Expect that names in an informant after using # `incorporate()` match a prescribed set of names - expect_true( - all( - names(informant_inc) == - c( - "tbl", "read_fn", "tbl_name", "info_label", - "meta_snippets", "lang", "locale", - "metadata", "metadata_rev" - ) + expect_named( + informant_inc, + c( + "tbl", "read_fn", "tbl_name", "info_label", "meta_snippets", "lang", + "locale", "metadata", "metadata_rev" ) ) @@ -74,7 +71,7 @@ test_that("Incorporating an informant yields the correct results", { expect_no_error( informant %>% set_tbl( - tbl = function() readr::read_csv(file = "test_table.csv", col_types = "TDdcddlc") + tbl = function() readr::read_csv(file = testthat::test_path("test_table.csv"), col_types = "TDdcddlc") ) %>% incorporate() ) @@ -87,7 +84,7 @@ test_that("Incorporating an informant yields the correct results", { informant_inc_2 <- informant_inc %>% set_tbl( - tbl = ~ readr::read_csv(file = "test_table_2.csv", col_types = "TDdcddlcd") + tbl = ~ readr::read_csv(file = test_path("test_table_2.csv"), col_types = "TDdcddlcd") ) %>% incorporate() @@ -109,7 +106,7 @@ test_that("Incorporating an informant from YAML yields the correct results", { # add information with some other `info_*()` functions informant <- create_informant( - tbl = ~ readr::read_csv(file = "test_table.csv", col_types = "TDdcddlc"), + tbl = ~ readr::read_csv(file = test_path("test_table.csv"), col_types = "TDdcddlc"), tbl_name = "test_table", label = "An example." ) %>% @@ -182,7 +179,7 @@ test_that("Incorporating an informant from YAML yields the correct results", { expect_no_error( informant_inc_yaml %>% set_tbl( - tbl = function() readr::read_csv(file = "test_table.csv", col_types = "TDdcddlc") + tbl = function() readr::read_csv(file = test_path("test_table.csv"), col_types = "TDdcddlc") ) %>% incorporate() ) diff --git a/tests/testthat/test-yaml_exec.R b/tests/testthat/test-yaml_exec.R index 823ea5c7e..4fa8729d6 100644 --- a/tests/testthat/test-yaml_exec.R +++ b/tests/testthat/test-yaml_exec.R @@ -91,7 +91,8 @@ test_that("The `yaml_exec()` function effectively processes .yml files", { # Copy the YAML files over to the working directory fs::file_copy( path = c(path_agent, path_informant, path_tbl_store), - new_path = getwd() + new_path = getwd(), + overwrite = TRUE ) # Read YAML files from the working directory, write output diff --git a/tests/testthat/test-yaml_read_informant.R b/tests/testthat/test-yaml_read_informant.R index 853799a6a..2e038011d 100644 --- a/tests/testthat/test-yaml_read_informant.R +++ b/tests/testthat/test-yaml_read_informant.R @@ -4,7 +4,7 @@ test_that("Reading an informant from YAML is possible", { # add information with some other `info_*()` functions informant <- create_informant( - tbl = ~ readr::read_csv(file = "test_table.csv", col_types = "TDdcddlc"), + tbl = ~ readr::read_csv(file = test_path("test_table.csv"), col_types = "TDdcddlc"), tbl_name = "test_table", label = "An example." ) %>%