Skip to content

Commit

Permalink
Fix lints
Browse files Browse the repository at this point in the history
Avoid old dplyr verbs
Fix rlang 0.3 deprecation warning
Remove workaround since pointblank imports gt 0.9.0
Remove partial amatching
  • Loading branch information
olivroy committed Nov 26, 2024
1 parent a85658b commit c12d6a4
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 39 deletions.
5 changes: 5 additions & 0 deletions R/col_vals_between.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 <-
Expand Down
6 changes: 6 additions & 0 deletions R/col_vals_not_between.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 <-
Expand Down
4 changes: 2 additions & 2 deletions R/get_agent_report.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
4 changes: 2 additions & 2 deletions R/get_multiagent_report.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -824,7 +824,7 @@ get_multiagent_report <- function(
)
)
) %>%
gt_missing(
gt::sub_missing(
columns = columns_not_used,
missing_text = ""
) %>%
Expand Down
7 changes: 6 additions & 1 deletion R/incorporate.R
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 6 additions & 6 deletions R/interrogate.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions R/scan_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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**", "<code>NA</code>", x)
Expand Down Expand Up @@ -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**", "<code>NA</code>", x)
Expand Down
4 changes: 4 additions & 0 deletions R/tbl_from_db.R
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,8 @@ db_tbl <- function(
x
}

# nolint start

RPostgres_driver <- function() {
rlang::check_installed("RPostgres", "to access a PostgreSQL table.")
RPostgres::Postgres()
Expand All @@ -538,6 +540,8 @@ RSQLite_driver <- function() {
RSQLite::SQLite()
}

# nolint end

unknown_driver <- function() {

stop(
Expand Down
2 changes: 1 addition & 1 deletion R/utils-profiling.R
Original file line number Diff line number Diff line change
Expand Up @@ -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**", "<code>NA</code>", x)
Expand Down
11 changes: 4 additions & 7 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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("<expr>", deparsed)
} else {
deparsed <- paste(deparse(expr, ...), collapse = collapse)
paste("<expr>", deparsed)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-get_informant_report.R
Original file line number Diff line number Diff line change
Expand Up @@ -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."
) %>%
Expand Down Expand Up @@ -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** 📦."
) %>%
Expand Down
23 changes: 10 additions & 13 deletions tests/testthat/test-incorporate_with_informant.R
Original file line number Diff line number Diff line change
Expand Up @@ -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."
) %>%
Expand Down Expand Up @@ -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"
)
)

Expand All @@ -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()
)
Expand All @@ -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()

Expand All @@ -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."
) %>%
Expand Down Expand Up @@ -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()
)
Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/test-yaml_exec.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-yaml_read_informant.R
Original file line number Diff line number Diff line change
Expand Up @@ -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."
) %>%
Expand Down

0 comments on commit c12d6a4

Please sign in to comment.