Skip to content

Commit a599557

Browse files
Progress deprecation of dcast/melt redirection (#6651)
1 parent dc7fb4d commit a599557

File tree

3 files changed

+9
-21
lines changed

3 files changed

+9
-21
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ rowwiseDT(
137137

138138
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).
139139

140+
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.
141+
140142
# data.table [v1.16.2](https://github.com/Rdatatable/data.table/milestone/35) (9 October 2024)
141143
142144
## BUG FIXES

R/fcast.R

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,10 @@ dcast <- function(
1212
data, formula, fun.aggregate = NULL, ..., margins = NULL,
1313
subset = NULL, fill = NULL, value.var = guess(data)
1414
) {
15-
if (is.data.table(data)) UseMethod("dcast", data)
16-
# nocov start
17-
else {
18-
data_name = deparse(substitute(data))
19-
ns = tryCatch(getNamespace("reshape2"), error=function(e)
20-
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))
21-
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)
22-
ns$dcast(data, formula, fun.aggregate = fun.aggregate, ..., margins = margins,
23-
subset = subset, fill = fill, value.var = value.var)
24-
}
25-
# nocov end
15+
# TODO(>=1.19.0): Remove this, just let dispatch to 'default' method fail.
16+
if (!is.data.table(data))
17+
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
18+
UseMethod("dcast", data)
2619
}
2720

2821
check_formula = function(formula, varnames, valnames, value.var.in.LHSdots, value.var.in.RHSdots) {

R/fmelt.R

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
# reshape2 dependency was originally abandoned because (1) we wanted to be in control
22
# of the R version dependency and (2) reshape2::dcast is not generic.
3-
# reshape2 package is deprecated since December 2017, so we'll deprecate our
3+
# reshape2 package is deprecated since December 2017, so we've deprecated our
44
# redirection as well
55

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

10+
# TODO(>=1.19.0): Remove this, just let dispatch to 'default' method fail.
1011
melt.default = function(data, ..., na.rm = FALSE, value.name = "value") {
11-
# if no registered method exists for data, attempts to redirect data to reshape2::melt;
12-
# CRAN package edarf and others fail without the redirection
13-
# nocov start
14-
data_name = deparse(substitute(data))
15-
ns = tryCatch(getNamespace("reshape2"), error=function(e)
16-
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))
17-
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)
18-
ns$melt(data, ..., na.rm=na.rm, value.name=value.name)
19-
# nocov end
12+
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
2013
}
2114

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

0 commit comments

Comments
 (0)