Skip to content

Commit

Permalink
Progress deprecation of dcast/melt redirection
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico authored Dec 10, 2024
1 parent 436bd6c commit 8878258
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 21 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ rowwiseDT(

6. `measurev()` was implemented and documented in v1.15.0, for use within `melt()`, and it is now exported (dependent packages can now use without a NOTE from CRAN check).

7. The `dcast()` and `melt()` generics no longer attempt to redirect to {reshape2} methods when passed non-`data.table`s. If you're still using {reshape2}, you must use namespace-qualification: `reshape2::dcast()`, `reshape2::melt()`. We have been warning about the deprecation since v1.12.4 (2019). Please note that {reshape2} is retired.
# data.table [v1.16.2](https://github.com/Rdatatable/data.table/milestone/35) (9 October 2024)
## BUG FIXES
Expand Down
15 changes: 4 additions & 11 deletions R/fcast.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,10 @@ dcast <- function(
data, formula, fun.aggregate = NULL, ..., margins = NULL,
subset = NULL, fill = NULL, value.var = guess(data)
) {
if (is.data.table(data)) UseMethod("dcast", data)
# nocov start
else {
data_name = deparse(substitute(data))
ns = tryCatch(getNamespace("reshape2"), error=function(e)
stopf("The %1$s generic in data.table has been passed a %2$s, but data.table::%1$s currently only has a method for data.tables. Please confirm your input is a data.table, with setDT(%3$s) or as.data.table(%3$s). If you intend to use a method from reshape2, try installing that package first, but do note that reshape2 is superseded and is no longer actively developed.", "dcast", class1(data), data_name))
warningf("The %1$s generic in data.table has been passed a %2$s and will attempt to redirect to the relevant reshape2 method; please note that reshape2 is superseded and is no longer actively developed, and this redirection is now deprecated. Please do this redirection yourself like reshape2::%1$s(%3$s). In the next version, this warning will become an error.", "dcast", class1(data), data_name)
ns$dcast(data, formula, fun.aggregate = fun.aggregate, ..., margins = margins,
subset = subset, fill = fill, value.var = value.var)
}
# nocov end
# TODO(>=1.19.0): Remove this, just let dispatch to 'default' method fail.
if (!is.data.table(data))
stopf("The %1$s generic in data.table has been passed a %2$s, but data.table::%1$s currently only has a method for data.tables. Please confirm your input is a data.table, with setDT(%3$s) or as.data.table(%3$s). If you intend to use a method from reshape2, try installing that package first, but do note that reshape2 is superseded and is no longer actively developed.", "dcast", class1(data), deparse(substitute(data))) # nocov
UseMethod("dcast", data)
}

check_formula = function(formula, varnames, valnames, value.var.in.LHSdots, value.var.in.RHSdots) {
Expand Down
13 changes: 3 additions & 10 deletions R/fmelt.R
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
# reshape2 dependency was originally abandoned because (1) we wanted to be in control
# of the R version dependency and (2) reshape2::dcast is not generic.
# reshape2 package is deprecated since December 2017, so we'll deprecate our
# reshape2 package is deprecated since December 2017, so we've deprecated our
# redirection as well

melt = function(data, ..., na.rm = FALSE, value.name = "value") {
UseMethod("melt", data)
}

# TODO(>=1.19.0): Remove this, just let dispatch to 'default' method fail.
melt.default = function(data, ..., na.rm = FALSE, value.name = "value") {
# if no registered method exists for data, attempts to redirect data to reshape2::melt;
# CRAN package edarf and others fail without the redirection
# nocov start
data_name = deparse(substitute(data))
ns = tryCatch(getNamespace("reshape2"), error=function(e)
stopf("The %1$s generic in data.table has been passed a %2$s, but data.table::%1$s currently only has a method for data.tables. Please confirm your input is a data.table, with setDT(%3$s) or as.data.table(%3$s). If you intend to use a method from reshape2, try installing that package first, but do note that reshape2 is superseded and is no longer actively developed.", "melt", class1(data), data_name))
warningf("The %1$s generic in data.table has been passed a %2$s and will attempt to redirect to the relevant reshape2 method; please note that reshape2 is superseded and is no longer actively developed, and this redirection is now deprecated. To continue using melt methods from reshape2 while both packages are attached, e.g. melt.list, you can prepend the namespace, i.e. reshape2::%1$s(%3$s). In the next version, this warning will become an error.", "melt", class1(data), data_name)
ns$melt(data, ..., na.rm=na.rm, value.name=value.name)
# nocov end
stopf("The %1$s generic in data.table has been passed a %2$s and will attempt to redirect to the relevant reshape2 method; please note that reshape2 is superseded and is no longer actively developed, and this redirection is now deprecated. To continue using melt methods from reshape2 while both packages are attached, e.g. melt.list, you can prepend the namespace, i.e. reshape2::%1$s(%3$s). In the next version, this warning will become an error.", "melt", class1(data), deparse(substitute(data))) # nocov
}

patterns = function(..., cols=character(0L), ignore.case=FALSE, perl=FALSE, fixed=FALSE, useBytes=FALSE) {
Expand Down

0 comments on commit 8878258

Please sign in to comment.