Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove reshape2 suggest #3081

Merged
merged 3 commits into from
Sep 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Authors@R: c(
person("Hugh","Parsonage", role="ctb"))
Depends: R (>= 3.1.0)
Imports: methods
Suggests: bit64, curl, knitr, xts, nanotime, zoo, reshape2
Suggests: bit64, curl, knitr, xts, nanotime, zoo
Description: Fast aggregation of large data (e.g. 100GB in RAM), fast ordered joins, fast add/modify/delete of columns by group using no copies at all, list columns, friendly and fast character-separated-value read/write. Offers a natural and flexible syntax, for faster development.
License: MPL-2.0 | file LICENSE
URL: http://r-datatable.com
Expand Down
23 changes: 11 additions & 12 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ export(rleid)
export(rleidv)
export(rowid)
export(rowidv)
export(as.xts.data.table)
if(getRversion() >= "3.6.0") S3method(xts::as.xts, data.table)
export(uniqueN)
export(setDTthreads, getDTthreads)
# set operators
Expand Down Expand Up @@ -69,7 +67,6 @@ S3method(as.data.table, ordered)
S3method(as.data.table, Date)
S3method(as.data.table, ITime)
S3method(as.data.table, table)
S3method(as.data.table, xts)
S3method(as.data.table, default)
S3method(as.data.frame, data.table)
S3method(as.list, data.table)
Expand All @@ -90,16 +87,12 @@ S3method(within, data.table)
S3method(is.na, data.table)
S3method(format, data.table)
S3method(Ops, data.table)

S3method(anyDuplicated, data.table)

export(split.data.table)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this really required? this was exported in 1.11.6 #2920 as per user request in a comment somewhere. As it is very recent it won't break much code, but NEWS entry would be useful.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A comment next to it explaining why and when exported would have been good because it's not proper to do so in addition to the S3method(split, data.table) which is still there. Should we consider exporting all methods for base generics as well as registering them?

Copy link
Member Author

@mattdowle mattdowle Sep 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a news item to 1.11.8 : #3083

S3method(split, data.table)

export(melt)
export(melt.data.table)
if(getRversion() >= "3.6.0") S3method(reshape2::melt, data.table) else S3method(melt, data.table)
S3method(melt, data.table)
export(dcast)
export(dcast.data.table)
S3method(dcast, data.table)

import(utils)
Expand All @@ -110,18 +103,24 @@ S3method(head, data.table)
import(stats)
S3method(na.omit, data.table)

S3method(as.data.table, xts)
if(getRversion() >= "3.6.0") {
export(as.xts.data.table) # fails in R-devel if not exported too, but I don't understand why
S3method(xts::as.xts, data.table) # delayed registration (new in R-devel) -- shouldn't this also export as.xts.data.table for us?
} else {
export(as.xts.data.table)
}

# IDateTime support:
export(as.IDate,as.ITime,IDateTime)
export(second,minute,hour,yday,wday,mday,week,isoweek,month,quarter,year)

export(as.Date.IDate) # workaround for zoo bug, see #1500

S3method("[", ITime)
S3method("+", IDate)
S3method("-", IDate)
S3method(as.character, ITime)
S3method(as.data.frame, ITime)
if(getRversion() >= "3.6.0") S3method(zoo::as.Date, IDate) else S3method(as.Date, IDate)
S3method(as.Date, IDate) # note that zoo::as.Date masks base::as.Date. Both generic. Causes trouble like #1500.
S3method(as.IDate, Date)
S3method(as.IDate, POSIXct)
S3method(as.IDate, default)
Expand Down
12 changes: 9 additions & 3 deletions R/fcast.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ 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)
else
reshape2::dcast(data, formula, fun.aggregate = fun.aggregate, ..., margins = margins,
subset = subset, fill = fill, value.var = value.var)
else {
# reshape2::dcast is not generic so we have to call it explicitly. See comments at the top of fmelt.R too.
# nocov start
ns = tryCatch(getNamespace("reshape2"), error=function(e)
stop("The dcast generic in data.table has been passed a ",class(data)[1L]," (not a data.table) but the reshape2 package is not installed to process this type. Please either install reshape2 and try again, or pass a data.table to dcast instead."))
ns$dcast(data, formula, fun.aggregate = fun.aggregate, ..., margins = margins,
subset = subset, fill = fill, value.var = value.var)
# nocov end
}
}

check_formula <- function(formula, varnames, valnames) {
Expand Down
12 changes: 7 additions & 5 deletions R/fmelt.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Add melt generic, don't import reshape2 as it requires R >= 3.0.0.

# melt is generic in reshape2 which is good (unlike dcast) but we still don't import reshape2 because reshape2's
# dependency on R 3.1 could change in a future release of reshape2. Say it started to depend on R 3.3. Users of data.table
# couldn't then install data.table in R 3.1 even if they only needed melt.data.table. The other reason is that
# reshape2::dcast is not generic (see that method in fcast.R).
melt <- function(data, ..., na.rm = FALSE, value.name = "value") {
if (is.data.table(data))
UseMethod("melt", data)
else
reshape2::melt(data, ..., na.rm=na.rm, value.name=value.name)
UseMethod("melt", data)
# if data is not data.table and reshape2 is installed, this will still dispatch to reshape2's method
}

patterns <- function(..., cols=character(0L)) {
Expand Down