Skip to content

Commit

Permalink
Deprecation messages (tidyverse#2791)
Browse files Browse the repository at this point in the history
* deprecation messages

for cleaner CRAN checks

* don't texpect warnings

* prefer inform()
  • Loading branch information
krlmlr committed May 17, 2017
1 parent 33d5236 commit e5b7d00
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 24 deletions.
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@

* Deprecated `failwith()`. I'm not even sure why it was here.

* Soft-deprecated `mutate_each()` and `summarise_each()`, these functions
print a message which will be changed to a warning in the next release.

* The `.env` argument to `sample_n()` and `sample_frac()` is defunct,
passing a value to this argument print a message which will be changed to a warning in the next release.

## Databases

This version of dplyr includes some major changes to how database connections work. By and large, you should be able to continue using your existing dplyr database code without modification, but there are two big changes that you should be aware of:
Expand Down
10 changes: 5 additions & 5 deletions R/colwise-mutate.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ check_dot_cols <- function(vars, cols) {
if (is_null(cols)) {
vars
} else {
warn("`.cols` has been renamed and is deprecated, please use `.vars`")
inform("`.cols` has been renamed and is deprecated, please use `.vars`")
if (missing(vars)) cols else vars
}
}
Expand Down Expand Up @@ -217,10 +217,10 @@ summarise_each_ <- function(tbl, funs, vars) {
Use `summarise_all()`, `summarise_at()` or `summarise_if()` instead."
)
if (is_empty(vars)) {
warn(glue(msg, "\nTo map `funs` over all variables, use `summarise_all()`"))
inform(glue(msg, "\nTo map `funs` over all variables, use `summarise_all()`"))
vars <- tbl_nongroup_vars(tbl)
} else {
warn(glue(msg, "\nTo map `funs` over a selection of variables, use `summarise_at()`"))
inform(glue(msg, "\nTo map `funs` over a selection of variables, use `summarise_at()`"))
vars <- compat_lazy_dots(vars, caller_env())
vars <- select_vars(tbl_nongroup_vars(tbl), !!! vars)
}
Expand Down Expand Up @@ -249,10 +249,10 @@ mutate_each_ <- function(tbl, funs, vars) {
Use `mutate_all()`, `mutate_at()` or `mutate_if()` instead."
)
if (is_empty(vars)) {
warn(glue(msg, "\nTo map `funs` over all variables, use `mutate_all()`"))
inform(glue(msg, "\nTo map `funs` over all variables, use `mutate_all()`"))
vars <- tbl_nongroup_vars(tbl)
} else {
warn(glue(msg, "\nTo map `funs` over a selection of variables, use `mutate_at()`"))
inform(glue(msg, "\nTo map `funs` over a selection of variables, use `mutate_at()`"))
vars <- compat_lazy_dots(vars, caller_env())
vars <- select_vars(tbl_nongroup_vars(tbl), !!! vars)
}
Expand Down
4 changes: 2 additions & 2 deletions R/dataframe.R
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ do_.data.frame <- function(.data, ..., .dots = list()) {
sample_n.data.frame <- function(tbl, size, replace = FALSE,
weight = NULL, .env = NULL) {
if (!is_null(.env)) {
warn("`.env` is deprecated and no longer has any effect")
inform("`.env` is deprecated and no longer has any effect")
}

weight <- eval_tidy(enquo(weight), tbl)
Expand All @@ -241,7 +241,7 @@ sample_n.data.frame <- function(tbl, size, replace = FALSE,
sample_frac.data.frame <- function(tbl, size = 1, replace = FALSE,
weight = NULL, .env = NULL) {
if (!is_null(.env)) {
warn("`.env` is deprecated and no longer has any effect")
inform("`.env` is deprecated and no longer has any effect")
}

weight <- eval_tidy(enquo(weight), tbl)
Expand Down
4 changes: 2 additions & 2 deletions R/grouped-df.r
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ sample_n.grouped_df <- function(tbl, size, replace = FALSE,

assert_that(is_scalar_integerish(size), size >= 0)
if (!is_null(.env)) {
warn("`.env` is deprecated and no longer has any effect")
inform("`.env` is deprecated and no longer has any effect")
}
weight <- enquo(weight)

Expand All @@ -284,7 +284,7 @@ sample_frac.grouped_df <- function(tbl, size = 1, replace = FALSE,
weight = NULL, .env = NULL) {
assert_that(is.numeric(size), length(size) == 1, size >= 0)
if (!is_null(.env)) {
warn("`.env` is deprecated and no longer has any effect")
inform("`.env` is deprecated and no longer has any effect")
}
if (size > 1 && !replace) {
bad_args("size", "of sampled fraction must be less or equal to one, ",
Expand Down
2 changes: 1 addition & 1 deletion R/join.r
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ common_by.NULL <- function(by, x, y) {
if (length(by) == 0) {
bad_args("by", "required, because the data sources have no common variables")
}
message("Joining, by = ", utils::capture.output(dput(by)))
inform(paste0("Joining, by = ", utils::capture.output(dput(by))))

list(
x = by,
Expand Down
2 changes: 1 addition & 1 deletion R/tbl-cube.r
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ guess_met <- function(df) {
met <- names(df)[is_num]
}

message("Using ", paste(met, collapse = ", "), " as measure column(s): use met_name to override.")
inform(paste0("Using ", paste(met, collapse = ", "), " as measure column(s): use `met_name` to override."))
met
}

Expand Down
2 changes: 1 addition & 1 deletion R/utils.r
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ succeeds <- function(x, quiet = FALSE) {
},
error = function(e) {
if (!quiet)
message("Error: ", e$message)
inform(paste0("Error: ", e$message))
FALSE
}
)
Expand Down
20 changes: 10 additions & 10 deletions tests/testthat/test-colwise-mutate.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,18 @@ test_that("can use a purrr-style lambda", {
test_that("_each() and _all() families agree", {
df <- data.frame(x = 1:3, y = 1:3)

expect_warning(expect_equal(summarise_each(df, funs(mean)), summarise_all(df, mean)), "deprecated")
expect_warning(expect_equal(summarise_each(df, funs(mean), x:y), summarise_at(df, vars(x:y), mean)), "deprecated")
expect_warning(expect_equal(summarise_each(df, funs(mean), z = y), summarise_at(df, vars(z = y), mean)), "deprecated")
expect_equal(summarise_each(df, funs(mean)), summarise_all(df, mean))
expect_equal(summarise_each(df, funs(mean), x:y), summarise_at(df, vars(x:y), mean))
expect_equal(summarise_each(df, funs(mean), z = y), summarise_at(df, vars(z = y), mean))

expect_warning(expect_equal(mutate_each(df, funs(mean)), mutate_all(df, mean)), "deprecated")
expect_warning(expect_equal(mutate_each(df, funs(mean), x:y), mutate_at(df, vars(x:y), mean)), "deprecated")
expect_warning(expect_equal(mutate_each(df, funs(mean), z = y), mutate_at(df, vars(z = y), mean)), "deprecated")
expect_equal(mutate_each(df, funs(mean)), mutate_all(df, mean))
expect_equal(mutate_each(df, funs(mean), x:y), mutate_at(df, vars(x:y), mean))
expect_equal(mutate_each(df, funs(mean), z = y), mutate_at(df, vars(z = y), mean))
})

test_that("specific directions are given for _all() and _at() versions", {
expect_warning(summarise_each(mtcars, funs(mean)), "over all variables")
expect_warning(summarise_each(mtcars, funs(mean), cyl), "over a selection of variables")
expect_warning(mutate_each(mtcars, funs(mean)), "over all variables")
expect_warning(mutate_each(mtcars, funs(mean), cyl), "over a selection of variables")
summarise_each(mtcars, funs(mean))
summarise_each(mtcars, funs(mean), cyl)
mutate_each(mtcars, funs(mean))
mutate_each(mtcars, funs(mean), cyl)
})
4 changes: 2 additions & 2 deletions tests/testthat/test-lazyeval-compat.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ test_that("lazydots are named and arrange() doesn't fail (it assumes empty names
})

test_that("mutate_each_() and summarise_each_() handle lazydots", {
expect_warning(cyl_chr <- mutate_each_(mtcars, funs(as.character), "cyl")$cyl, "deprecated")
cyl_chr <- mutate_each_(mtcars, funs(as.character), "cyl")$cyl
expect_identical(cyl_chr, as.character(mtcars$cyl))

expect_warning(cyl_mean <- summarise_each_(mtcars, funs(mean), "cyl")$cyl, "deprecated")
cyl_mean <- summarise_each_(mtcars, funs(mean), "cyl")$cyl
expect_equal(cyl_mean, mean(mtcars$cyl))
})

Expand Down

0 comments on commit e5b7d00

Please sign in to comment.