-
Notifications
You must be signed in to change notification settings - Fork 990
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
Search registered S3 method for melt before redirecting to reshape2 #4864
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4864 +/- ##
==========================================
- Coverage 99.54% 99.54% -0.01%
==========================================
Files 76 76
Lines 14692 14691 -1
==========================================
- Hits 14625 14624 -1
Misses 67 67
Continue to review full report at Codecov.
|
0205a52
to
ee35980
Compare
R/fmelt.R
Outdated
data_name = deparse(substitute(data)) | ||
ns = tryCatch(getNamespace("reshape2"), error=function(e) | ||
stop("The melt generic in data.table has been passed a ", class(data)[1L],", but data.table::melt currently only has a method for data.tables. Please confirm your input is a data.table, with setDT(", data_name, ") or as.data.table(", data_name, "). If you intend to use a method from reshape2, try installing that package first, but do note that reshape2 is deprecated and you should be migrating your code away from using it.")) | ||
warning("The melt generic in data.table has been passed a ", class(data)[1L], " and will attempt to redirect to the relevant reshape2 method; please note that reshape2 is deprecated, and this redirection is now deprecated as well. To continue using melt methods from reshape2 while both libraries are attached, e.g. melt.list, you can prepend the namespace like reshape2::melt(", data_name, "). In the next version, this warning will become an error.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we are now going into new major version so this code could be simplified for raising error, as mentioned in the warning already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean stopping the redirection towards reshape2
?
Committed some additional changes and resolved conflicts. I still think having melt as a generic method makes sense. For example, it could serve to melt an S3 object containing multiple tables and matrices into a single long "melted" format. I have added a note regarding the change in the NEWS and I added a test on melt.default in test.Rraw. I think that retaining the redirection towards reshape2 is still useful. As Hadley mentioned in #4908, reshape2 will remain functional for the foreseeable future. Please let me know if there is anything I missed in this pull request. |
Thanks @odelmarcelle. Please let me know if your name is different to your id, for the contributor list displayed on CRAN. Have invited you to be project member too: it should be a button in your GitHub profile or projects page that you need to click to accept. |
Thank you for reviewing and merging @mattdowle. Although I'm not sure I deserve to be listed in the contributor list for such a small input, my actual name is different from my Github username. Could you perhaps correct my name to "Olivier Delmarcelle"? I corrected the DESCRIPTION file on my forked branch, but I'm not sure how to propagate this to the master branch now that this pull request is merged. Sorry for the trouble! |
Thanks @odelmarcelle, done in 76cfe11. |
Follow-up of #3633 and #3763
The condition leading to
UseMethod
in themelt
generic is not true for non-data.table
object. Hence, S3 methods formelt
defined by other packages may be skipped.I initially suggested changing that condition in order to search if a S3 method exists for the current object before redirecting to
reshape2
.After giving it a second thought, it appears more correct to performs the redirection to
reshape2
in adefault
method. This leaves the generic clean and allows registering new methods.Since there were no tests on the generic
melt
, I left the test file as-is.After the change, using S3 method dispatch on a custom object works as intended: