From ec3cd3cd05d0918fa58b91b380c6af3fff47ee24 Mon Sep 17 00:00:00 2001 From: Olivier Roy Date: Fri, 2 Jun 2023 14:33:57 -0400 Subject: [PATCH] Simple code update. --- R/adorn_totals.R | 3 +-- R/remove_empties.R | 4 ++-- man/remove_constant.Rd | 2 +- man/remove_empty.Rd | 2 +- tests/testthat/test-clean-names.R | 2 +- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/R/adorn_totals.R b/R/adorn_totals.R index fb1e8cf6..e4ffe06d 100644 --- a/R/adorn_totals.R +++ b/R/adorn_totals.R @@ -143,8 +143,7 @@ adorn_totals <- function(dat, where = "row", fill = "-", na.rm = TRUE, name = "T if ("col" %in% where) { # Add totals col row_totals <- dat %>% - dplyr::select(dplyr::all_of(cols_to_total)) %>% - dplyr::select_if(is.numeric) %>% + dplyr::select(dplyr::all_of(cols_to_total) & dplyr::where(is.numeric)) %>% dplyr::transmute(Total = rowSums(., na.rm = na.rm)) dat[[name[2]]] <- row_totals$Total diff --git a/R/remove_empties.R b/R/remove_empties.R index 68de3c4e..eac97498 100644 --- a/R/remove_empties.R +++ b/R/remove_empties.R @@ -27,7 +27,7 @@ #' dd %>% remove_empty("rows") #' # solution: preprocess to convert whitespace/empty strings to NA, #' # _then_ remove empty (all-NA) rows -#' dd %>% mutate(across(is.character,~na_if(trimws(.),""))) %>% +#' dd %>% mutate(across(where(is.character),~na_if(trimws(.),""))) %>% #' remove_empty("rows") #' @export remove_empty <- function(dat, which = c("rows", "cols"), cutoff=1, quiet=TRUE) { @@ -93,7 +93,7 @@ remove_empty <- function(dat, which = c("rows", "cols"), cutoff=1, quiet=TRUE) { #' #' # To find the columns that are constant #' data.frame(A=1, B=1:3) %>% -#' dplyr::select_at(setdiff(names(.), names(remove_constant(.)))) %>% +#' dplyr::select(!dplyr::all_of(names(remove_constant(.)))) %>% #' unique() #' @importFrom stats na.omit #' @family remove functions diff --git a/man/remove_constant.Rd b/man/remove_constant.Rd index afb155eb..f4d7e17f 100644 --- a/man/remove_constant.Rd +++ b/man/remove_constant.Rd @@ -24,7 +24,7 @@ remove_constant(data.frame(A=1, B=1:3)) # To find the columns that are constant data.frame(A=1, B=1:3) \%>\% - dplyr::select_at(setdiff(names(.), names(remove_constant(.)))) \%>\% + dplyr::select(!dplyr::all_of(names(remove_constant(.)))) \%>\% unique() } \seealso{ diff --git a/man/remove_empty.Rd b/man/remove_empty.Rd index 8f9e4318..08e358f5 100644 --- a/man/remove_empty.Rd +++ b/man/remove_empty.Rd @@ -38,7 +38,7 @@ dd <- tibble(x=c(LETTERS[1:5],NA,rep("",2)), dd \%>\% remove_empty("rows") # solution: preprocess to convert whitespace/empty strings to NA, # _then_ remove empty (all-NA) rows -dd \%>\% mutate(across(is.character,~na_if(trimws(.),""))) \%>\% +dd \%>\% mutate(across(where(is.character),~na_if(trimws(.),""))) \%>\% remove_empty("rows") } \seealso{ diff --git a/tests/testthat/test-clean-names.R b/tests/testthat/test-clean-names.R index e3a98927..00bf0bff 100644 --- a/tests/testthat/test-clean-names.R +++ b/tests/testthat/test-clean-names.R @@ -589,7 +589,7 @@ test_that("tbl_graph/tidygraph", { tidygraph::play_erdos_renyi(10, 0.5) %>% # create nodes wi tidygraph::bind_nodes(test_df) %>% - tidygraph::mutate_all(tidyr::replace_na, 1) + dplyr::mutate(dplyr::across(dplyr::where(is.numeric), ~ dplyr::coalesce(x, 1))) # create a graph with clean names # warning due to unhandled mu