diff --git a/NEWS.md b/NEWS.md index a3f71cbe67..7e8b895f2d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -149,6 +149,8 @@ rowwiseDT( 11. Deprecation of `fread(autostart=)` has been upgraded to an error. It has been warning since v1.11.0 (6 years ago). The argument will be removed in the next release. +12. Deprecation of `droplevels(in.place=TRUE)` (warning since v1.16.0) has been upgraded from warning to error. The argument will be removed in the next release. + # data.table [v1.16.4](https://github.com/Rdatatable/data.table/milestone/36) 4 December 2024 ## BUG FIXES diff --git a/R/fdroplevels.R b/R/fdroplevels.R index 3116a3f85f..642b76e090 100644 --- a/R/fdroplevels.R +++ b/R/fdroplevels.R @@ -8,10 +8,9 @@ fdroplevels = function(x, exclude = if (anyNA(levels(x))) NULL else NA, ...) { return(ans) } -droplevels.data.table = function(x, except=NULL, exclude, in.place=FALSE, ...){ - stopifnot(is.logical(in.place)) - if (isTRUE(in.place)) warningf("droplevels() with in.place=TRUE is deprecated. Use setdroplevels() instead.") - if (!in.place) x = copy(x) +droplevels.data.table = function(x, except=NULL, exclude, in.place=NULL, ...){ + if (!is.null(in.place)) stopf("droplevels() with in.place=TRUE is deprecated. Use setdroplevels() instead.") + x = copy(x) if (missing(exclude)) exclude = NULL setdroplevels(x, except, exclude)[] } diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 004f6c8ea6..4153b79125 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -17785,7 +17785,7 @@ if (base::getRversion() >= "3.4.0") { } test(2214.06, droplevels(DT)[["a"]], droplevels(DT[1:5,a])) test(2214.07, droplevels(DT, 1)[["a"]], x[1:5]) -test(2214.08, droplevels(DT, in.place=TRUE), DT, warning="droplevels() with in.place=TRUE is deprecated.") +test(2214.08, droplevels(DT, in.place=TRUE), error="droplevels() with in.place=TRUE is deprecated.") # support ordered factors in fdroplevels o = factor(letters[1:10], ordered=TRUE) test(2214.09, fdroplevels(o[1:5]), droplevels(o[1:5])) diff --git a/man/fdroplevels.Rd b/man/fdroplevels.Rd index 724399d20a..4a7423a44c 100644 --- a/man/fdroplevels.Rd +++ b/man/fdroplevels.Rd @@ -12,13 +12,13 @@ fdroplevels(x, exclude = if (anyNA(levels(x))) NULL else NA, \dots) setdroplevels(x, except = NULL, exclude = NULL) -\method{droplevels}{data.table}(x, except = NULL, exclude, in.place = FALSE, \dots) +\method{droplevels}{data.table}(x, except = NULL, exclude, in.place = NULL, \dots) } \arguments{ \item{x}{ \code{factor} or \code{data.table} where unused levels should be dropped. } \item{exclude}{ A \code{character} vector of factor levels which are dropped no matter of presented or not. } \item{except}{ An \code{integer} vector of indices of data.table columns which are not modified by dropping levels. } - \item{in.place}{ logical (default is \code{FALSE}). If \code{TRUE} levels of factors of \code{data.table} are modified in-place. } + \item{in.place}{ Deprecated. Use \code{setdroplevels} for in-place modification. } \item{\dots}{ further arguments passed to methods } }