Skip to content

Commit

Permalink
Remove warnings and fallback behavior for deprecated type and `dict…
Browse files Browse the repository at this point in the history
…` args in `vars_funs.R`
  • Loading branch information
jeancochrane committed Dec 5, 2024
1 parent f628b70 commit 3d94d7e
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 110 deletions.
36 changes: 2 additions & 34 deletions R/vars_funs.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@
#' @param output_type Output type. Either \code{"inplace"}, which renames the
#' input data frame, or \code{"vector"}, which returns a named character
#' vector with the construction new_col_name = old_col_name.
#' @param type Deprecated. Use \code{output_type} instead.
#' @param dictionary The dictionary used to translate names. Uses
#' \code{\link{vars_dict}} by default. Use \code{\link{vars_dict_legacy}} for
#' legacy data column names.
#' @param dict Deprecated. Use \code{dictionary} instead.
#'
#' @return The input data frame with columns renamed.
#'
Expand Down Expand Up @@ -77,21 +75,7 @@ vars_rename <- function(data,
names_from = NULL,
names_to = NULL,
output_type = "inplace",
dictionary = ccao::vars_dict,
# Deprecated args
type = NULL,
dict = NULL) {
# Check if deprecated arguments are used and override values if so
if (!is.null(type)) {
warning("'type' is deprecated. Use 'output_type' instead.", call. = FALSE)
output_type <- type
}

if (!is.null(dict)) {
warning("'dict' is deprecated. Use 'dictionary' instead.", call. = FALSE)
dictionary <- dict
}

dictionary = ccao::vars_dict) {
# Check input data dictionary
stopifnot(
is.data.frame(dictionary),
Expand Down Expand Up @@ -169,14 +153,12 @@ vars_rename <- function(data,
#' names. Looks for all columns with numerically encoded character
#' values by default.
#' @param code_type Output/recode type. See description for options.
#' @param type Deprecated. Use \code{code_type} instead.
#' @param as_factor If \code{TRUE}, re-encoded values will be returned as
#' factors with their levels pre-specified by the dictionary. Otherwise, will
#' return re-encoded values as characters only.
#' @param dictionary The dictionary used to translate encodings. Uses
#' \code{\link{vars_dict}} by default. Use \code{\link{vars_dict_legacy}} for
#' legacy data column encodings.
#' @param dict Deprecated. Use \code{dictionary} instead.
#'
#' @note Values which are in the data but are NOT in \code{\link{vars_dict}}
#' will be converted to NA. For example, there is no numeric value 3 for AIR,
Expand Down Expand Up @@ -238,21 +220,7 @@ vars_recode <- function(data,
cols = dplyr::everything(),
code_type = "long",
as_factor = TRUE,
dictionary = ccao::vars_dict,
# Deprecated args
type = NULL,
dict = NULL) {
# Check if deprecated arguments are used and override values if so
if (!is.null(type)) {
warning("'type' is deprecated. Use 'code_type' instead.", call. = FALSE)
code_type <- type
}

if (!is.null(dict)) {
warning("'dict' is deprecated. Use 'dictionary' instead.", call. = FALSE)
dictionary <- dict
}

dictionary = ccao::vars_dict) {
# Check input data dictionary
stopifnot(
is.data.frame(dictionary),
Expand Down
8 changes: 1 addition & 7 deletions man/vars_recode.Rd

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

8 changes: 1 addition & 7 deletions man/vars_rename.Rd

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

62 changes: 0 additions & 62 deletions tests/testthat/test-vars_funs.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,44 +80,6 @@ test_that("output is as expected", {
)
})

test_that("deprecation warnings get emitted", {
expect_warning(
vars_rename(
data = chars_sample_athena[, 14:19],
names_from = "athena",
names_to = "pretty",
type = "vector"
),
"'type' is deprecated"
)
expect_warning(
vars_rename(
data = chars_sample_athena[, 14:19],
names_from = "athena",
names_to = "pretty",
dict = ccao::vars_dict
),
"'dict' is deprecated"
)
# Test that the deprecated params produce the same output as the new params
expect_equal(
vars_rename(
data = chars_sample_athena[, 14:19],
names_from = "athena",
names_to = "pretty",
type = "vector",
dict = ccao::vars_dict
),
vars_rename(
data = chars_sample_athena[, 14:19],
names_from = "athena",
names_to = "pretty",
output_type = "vector",
dictionary = ccao::vars_dict
)
)
})

# Test that invalid inputs throw errors
test_that("invalid data types stop process", {
expect_condition(vars_rename(1))
Expand Down Expand Up @@ -294,30 +256,6 @@ test_that("output is as expected", {
)
})

test_that("deprecation warnings get emitted", {
expect_warning(
vars_recode(data = recode_test_data_athena, type = "short"),
"'type' is deprecated"
)
expect_warning(
vars_recode(data = recode_test_data_athena, dict = ccao::vars_dict),
"'dict' is deprecated"
)
# Test that the deprecated params produce the same output as the new params
expect_equal(
vars_recode(
data = recode_test_data_athena,
type = "short",
dict = ccao::vars_dict
),
vars_recode(
data = recode_test_data_athena,
code_type = "short",
dictionary = ccao::vars_dict
)
)
})

# Test that invalid inputs throw errors
test_that("invalid data types stop process", {
expect_error(
Expand Down

0 comments on commit 3d94d7e

Please sign in to comment.