Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated arguments #927

Merged
merged 6 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions R/export_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
#' if `table_width` is numeric and table rows are larger than `table_width`,
#' the table is split into two parts.
#' @param ... Currently not used.
#' @param group_by Deprecated, please use `by` instead.
#' @inheritParams format_value
#' @inheritParams get_data
#'
Expand Down Expand Up @@ -102,7 +101,7 @@
#' export_table(d, width = c(x = 5, z = 10))
#' export_table(d, width = c(x = 5, y = 5, z = 10), align = "lcr")
#' @export
export_table <- function(x,

Check warning on line 104 in R/export_table.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/export_table.R,line=104,col=1,[cyclocomp_linter] Reduce the cyclomatic complexity of this function from 78 to at most 40.
sep = " | ",
header = "-",
cross = NULL,
Expand All @@ -118,7 +117,6 @@
footer = NULL,
align = NULL,
by = NULL,
group_by = NULL,
zap_small = FALSE,
table_width = NULL,
verbose = TRUE,
Expand All @@ -133,12 +131,6 @@
format <- "markdown"
}

## TODO: deprecate later
if (!is.null(group_by)) {
format_warning("Argument `group_by` is deprecated and will be removed in a future release. Please use `by` instead.") # nolint
by <- group_by
}

# validation check
if (is.null(x) || (is.data.frame(x) && nrow(x) == 0) || is_empty_object(x)) {
if (isTRUE(verbose)) {
Expand Down Expand Up @@ -474,7 +466,7 @@
# plain text formatting ------------------------


.format_basic_table <- function(final,

Check warning on line 469 in R/export_table.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/export_table.R,line=469,col=1,[cyclocomp_linter] Reduce the cyclomatic complexity of this function from 70 to at most 40.
header,
sep,
cross = NULL,
Expand Down Expand Up @@ -577,14 +569,14 @@

# width of first table row of complete table. Currently, "final" is still
# a matrix, so we need to paste the columns of the first row into a string
row_width <- nchar(paste0(final[1, ], collapse = sep), type = "width")

Check warning on line 572 in R/export_table.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/export_table.R,line=572,col=24,[paste_linter] Use paste(), not paste0(), to collapse a character vector when sep= is not used.

# possibly first split - all table columns longer than "line_width"
# (i.e. first table row) go into a second string
if (row_width > line_width) {
i <- 1
# determine how many columns fit into the first line
while (nchar(paste0(final[1, 1:i], collapse = sep), type = "width") < line_width) {

Check warning on line 579 in R/export_table.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/export_table.R,line=579,col=20,[paste_linter] Use paste(), not paste0(), to collapse a character vector when sep= is not used.
i <- i + 1
}
# copy first column, and all columns that did not fit into the first line
Expand All @@ -596,14 +588,14 @@
}

# width of first table row of remaing second table part
row_width <- nchar(paste0(final2[1, ], collapse = sep), type = "width")

Check warning on line 591 in R/export_table.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/export_table.R,line=591,col=24,[paste_linter] Use paste(), not paste0(), to collapse a character vector when sep= is not used.

# possibly second split - all table columns longer than "line_width"
# (i.e. first table row) go into a third string - we repeat the same
# procedure as above
if (row_width > line_width) {
i <- 1
while (nchar(paste0(final2[1, 1:i], collapse = sep), type = "width") < line_width) {

Check warning on line 598 in R/export_table.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/export_table.R,line=598,col=20,[paste_linter] Use paste(), not paste0(), to collapse a character vector when sep= is not used.
i <- i + 1
}
if (i > 2 && i < ncol(final2)) {
Expand Down Expand Up @@ -674,7 +666,7 @@
for (row in seq_len(nrow(final))) {
# create a string for each row, where cells from original matrix are
# separated by the separator char
final_row <- paste0(final[row, ], collapse = sep)

Check warning on line 669 in R/export_table.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/export_table.R,line=669,col=18,[paste_linter] Use paste(), not paste0(), to collapse a character vector when sep= is not used.
# check if we have an empty row, and if so, fill with an
# "empty line separator", if requested by user
if (!is.null(empty_line) && !any(nzchar(trim_ws(final[row, ])))) {
Expand All @@ -685,7 +677,7 @@
# the empty line, which is just empty cells with separator char,
# will now be replaced by the "empty line char", so we have a
# clean separator line
paste0(rep_len(empty_line, nchar(final_row, type = "width")), collapse = ""),

Check warning on line 680 in R/export_table.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/export_table.R,line=680,col=9,[paste_linter] Use paste(), not paste0(), to collapse a character vector when sep= is not used.
cross, sep, final_row,
is_last_row = row == nrow(final)
)
Expand All @@ -699,7 +691,7 @@
# check whether user wants to have a "cross" char where vertical and
# horizontal lines (from header line) cross.
header_line <- .insert_cross(
paste0(rep_len(header, nchar(final_row, type = "width")), collapse = ""),

Check warning on line 694 in R/export_table.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/export_table.R,line=694,col=9,[paste_linter] Use paste(), not paste0(), to collapse a character vector when sep= is not used.
cross, sep, final_row,
is_last_row = row == nrow(final)
)
Expand Down Expand Up @@ -817,7 +809,7 @@

# markdown formatting -------------------

.format_markdown_table <- function(final,

Check warning on line 812 in R/export_table.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/export_table.R,line=812,col=1,[cyclocomp_linter] Reduce the cyclomatic complexity of this function from 43 to at most 40.
x,
caption = NULL,
subtitle = NULL,
Expand Down
15 changes: 0 additions & 15 deletions R/get_datagrid.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@
#' @param verbose Toggle warnings.
#' @param ... Arguments passed to or from other methods (for instance, `length`
#' or `range` to control the spread of numeric variables.).
#' @param at Deprecated. Use `by` instead.
#'
#' @return Reference grid data frame.
#'
Expand Down Expand Up @@ -197,14 +196,7 @@ get_datagrid.data.frame <- function(x,
reference = x,
length = 10,
range = "range",
at,
...) {
## TODO: deprecate later
if (!missing(at)) {
format_warning("Argument `at` is deprecated and will be removed in a future release. Please use `by` instead.") # nolint
by <- at
}

# find numerics that were coerced to factor in-formula
numeric_factors <- colnames(x)[vapply(x, function(i) isTRUE(attributes(i)$factor), logical(1))]

Expand Down Expand Up @@ -494,14 +486,7 @@ get_datagrid.default <- function(x,
include_response = FALSE,
data = NULL,
verbose = TRUE,
at,
...) {
## TODO: deprecate later
if (!missing(at)) {
format_warning("Argument `at` is deprecated and will be removed in a future release. Please use `by` instead.") # nolint
by <- at
}

# validation check
if (!is_model(x)) {
format_error("`x` must be a statistical model.")
Expand Down
26 changes: 0 additions & 26 deletions R/get_varcov_sandwich.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,10 @@
...) {
dots <- list(...)

## TODO: remove deprecated warnings in a future update

# deprecated
if (isTRUE(verbose) && "vcov_type" %in% names(dots)) {
format_warning("The `vcov_type` argument is superseded by the `vcov_args` argument.")
}
if (isTRUE(verbose) && "robust" %in% names(dots)) {
format_warning("The `robust` argument is superseded by the `vcov` argument.")
}

if (is.null(vcov_args)) {
vcov_args <- list()
}

# deprecated: `vcov_estimation`
if (is.null(vcov_fun) && "vcov_estimation" %in% names(dots)) {
vcov_fun <- dots[["vcov_estimation"]]
}

# deprecated: `robust`
if (isTRUE(dots[["robust"]]) && is.null(vcov_fun)) {
dots[["robust"]] <- NULL
vcov_fun <- "HC3"
}

# deprecated: `vcov_type`
if ("vcov_type" %in% names(dots) && !"type" %in% names(vcov_args)) {
vcov_args[["type"]] <- dots[["vcov_type"]]
}

# vcov_fun is a matrix
if (is.matrix(vcov_fun)) {
return(vcov_fun)
Expand Down
10 changes: 1 addition & 9 deletions R/print_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
#' and `subtitles` may be any length from 1 to same length as returned
#' list elements. If `titles` and `subtitles` are shorter than
#' existing elements, only the first default attributes are overwritten.
#' @param split_by Deprecated, please use `by` instead.
#'
#' @return
#'
Expand Down Expand Up @@ -110,14 +109,7 @@ print_parameters <- function(x,
keep_parameter_column = TRUE,
remove_empty_column = FALSE,
titles = NULL,
subtitles = NULL,
split_by = NULL) {
## TODO: deprecte later
if (!is.null(split_by)) {
format_warning("Argument `split_by` is deprecated and will be removed in a future release. Please use `by` instead.") # nolint
by <- split_by
}

subtitles = NULL) {
obj <- list(...)

# save attributes of original object
Expand Down
12 changes: 6 additions & 6 deletions R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ n_unique <- function(x, ...) {

#' @rdname trim_ws
#' @export
n_unique.default <- function(x, remove_na = TRUE, na.rm = remove_na, ...) {
n_unique.default <- function(x, remove_na = TRUE, na.rm = TRUE, ...) {
if (is.null(x)) {
return(0)
}
Expand All @@ -103,23 +103,23 @@ n_unique.default <- function(x, remove_na = TRUE, na.rm = remove_na, ...) {
}

#' @export
n_unique.data.frame <- function(x, remove_na = TRUE, na.rm = remove_na, ...) {
n_unique.data.frame <- function(x, remove_na = TRUE, na.rm = TRUE, ...) {
## TODO:: remove deprecation warning later
if (!missing(na.rm)) {
format_warning("The `na.rm` argument is deprecated. Use `remove_na` instead.")
remove_na <- na.rm
}
vapply(x, n_unique, na.rm = remove_na, FUN.VALUE = numeric(1L))
vapply(x, n_unique, remove_na = remove_na, FUN.VALUE = numeric(1L))
}

#' @export
n_unique.list <- function(x, remove_na = TRUE, na.rm = remove_na, ...) {
n_unique.list <- function(x, remove_na = TRUE, na.rm = TRUE, ...) {
## TODO:: remove deprecation warning later
if (!missing(na.rm)) {
format_warning("The `na.rm` argument is deprecated. Use `remove_na` instead.")
remove_na <- na.rm
}
lapply(x, n_unique, na.rm = remove_na)
lapply(x, n_unique, remove_na = remove_na)
}


Expand Down Expand Up @@ -155,7 +155,7 @@ safe_deparse_symbol <- function(x) {

#' @rdname trim_ws
#' @export
has_single_value <- function(x, remove_na = FALSE, na.rm = remove_na, ...) {
has_single_value <- function(x, remove_na = FALSE, na.rm = TRUE, ...) {
## TODO:: remove deprecation warning later
if (!missing(na.rm)) {
format_warning("The `na.rm` argument is deprecated. Use `remove_na` instead.")
Expand Down
3 changes: 0 additions & 3 deletions man/export_table.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions man/get_datagrid.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions man/print_parameters.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/trim_ws.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 13 additions & 20 deletions tests/testthat/test-get_datagrid.R
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ test_that("get_datagrid - emmeans", {
# emm_list
em1 <- emmeans::emmeans(mod1, pairwise ~ cyl | hp, at = list(hp = hp_vals))
em2 <- emmeans::emmeans(mod1, pairwise ~ cyl | hp, at = list(hp = hp_vals), regrid = TRUE)
em3 <- emmeans::emmeans(mod2, pairwise ~ cyl | hp, at = list(hp = hp_vals))
em3 <- emmeans::emmeans(mod2, pairwise ~ cyl | hp, at = list(hp = hp_vals))

res <- get_datagrid(em1)
expect_identical(res, get_datagrid(em2))
Expand All @@ -268,10 +268,14 @@ test_that("get_datagrid - marginaleffects", {
mod1 <- glm(am ~ hp + factor(cyl), family = binomial("logit"), data = mtcars)
mod2 <- lm(mpg ~ hp + factor(cyl), data = mtcars)

mp1 <- marginaleffects::avg_predictions(mod1, variables = list("hp" = c(50, 100)),
by = c("cyl", "hp"))
mp2 <- marginaleffects::avg_predictions(mod2, variables = list("hp" = c(50, 100),
cyl = unique))
mp1 <- marginaleffects::avg_predictions(mod1,
variables = list(hp = c(50, 100)),
by = c("cyl", "hp")
)
mp2 <- marginaleffects::avg_predictions(mod2, variables = list(
hp = c(50, 100),
cyl = unique
))

res <- get_datagrid(mp1)
expect_s3_class(res, "data.frame")
Expand All @@ -290,9 +294,10 @@ test_that("get_datagrid - marginaleffects", {

mod <- lm(mpg ~ wt + hp + qsec, data = mtcars)
myme <- marginaleffects::comparisons(mod,
variables = c("wt", "hp"),
cross = TRUE,
newdata = marginaleffects::datagrid(qsec = range))
variables = c("wt", "hp"),
cross = TRUE,
newdata = marginaleffects::datagrid(qsec = range)
)
res <- get_datagrid(myme)
expect_true(all(c("wt", "mpg", "hp", "qsec") %in% colnames(res)))
expect_true(all(c("contrast_hp", "contrast_wt") %in% colnames(res)))
Expand Down Expand Up @@ -396,15 +401,3 @@ test_that("get_datagrid - multiple weight variables", {
tolerance = 1e-3
)
})


test_that("get_datagrid - deprecated arg doesn't cause memory allocation issues", {
data(iris)
expect_warning(
{
out <- get_datagrid(iris, at = NULL)
},
regex = "Argument `at` is deprecated"
)
expect_identical(nrow(out), 1L)
})
12 changes: 5 additions & 7 deletions tests/testthat/test-get_predicted.R
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ test_that("robust vcov", {
skip_if_not_installed("sandwich")
mod <- lm(mpg ~ hp, data = mtcars)
se0 <- get_predicted_se(mod)
se1 <- suppressWarnings(get_predicted_se(mod, vcov_estimation = "HC"))
se2 <- suppressWarnings(get_predicted_se(mod, vcov_estimation = "HC", vcov_type = "HC3"))
se1 <- suppressWarnings(get_predicted_se(mod, vcov = "HC"))
se2 <- suppressWarnings(get_predicted_se(mod, vcov = "HC3"))
se3 <- get_predicted_se(mod, vcov = "HC", vcov_args = list(type = "HC3"))
expect_true(all(se0 != se1))
expect_true(all(se1 == se2))
Expand All @@ -173,13 +173,11 @@ test_that("robust vcov", {
ignore_attr = TRUE
)
# various user inputs
se1 <- suppressWarnings(get_predicted_se(mod, vcov_estimation = "HC", vcov_type = "HC2"))
se2 <- get_predicted_se(mod, vcov = "HC2")
se3 <- get_predicted_se(mod, vcov = "vcovHC", vcov_args = list(type = "HC2"))
se4 <- get_predicted_se(mod, vcov = sandwich::vcovHC, vcov_args = list(type = "HC2"))
se1 <- get_predicted_se(mod, vcov = "HC2")
se2 <- get_predicted_se(mod, vcov = "vcovHC", vcov_args = list(type = "HC2"))
se3 <- get_predicted_se(mod, vcov = sandwich::vcovHC, vcov_args = list(type = "HC2"))
expect_true(all(se1 == se2))
expect_true(all(se1 == se3))
expect_true(all(se1 == se4))
se1 <- get_predicted_se(mod, vcov = "HC1")
se2 <- get_predicted_se(mod, vcov = sandwich::vcovHC, vcov_args = list(type = "HC1"))
expect_true(all(se1 == se2))
Expand Down
Loading