fix docs/errors for melt, measure, patterns, eval_with_cols: cols arg should not be provided by user#5115
fix docs/errors for melt, measure, patterns, eval_with_cols: cols arg should not be provided by user#5115
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5115 +/- ##
==========================================
- Coverage 97.51% 97.49% -0.03%
==========================================
Files 80 80
Lines 14920 14864 -56
==========================================
- Hits 14549 14491 -58
- Misses 371 373 +2 ☔ View full report in Codecov by Sentry. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
|
So rather than adding logic to measure/measurev to try to detect the missing cols arg (which would not be possible, given that it is filled in via NSE), I implemented an error message in |
|
The new behavior is the error message below, which was previously not present, but now clearly indicates that the user should remove the cols argument in their code. > i1=data.table(iris)[1]
> melt(i1, measure=patterns("Sepal"))
Petal.Length Petal.Width Species variable value
<num> <num> <fctr> <fctr> <num>
1: 1.4 0.2 setosa Sepal.Length 5.1
2: 1.4 0.2 setosa Sepal.Width 3.5
> melt(i1, measure=patterns("Sepal", cols=names(iris)))
Erreur : user should not provide cols argument to patterns |
Co-authored-by: Michael Chirico <michaelchirico4@gmail.com>
| if ("cols" %in% names(formals(fun)) && !"cols" %in% names(named_call)) { | ||
| if ("cols" %in% names(formals(fun))) { | ||
| if ("cols" %in% names(named_call)) { | ||
| stopf("user should not provide cols argument to %s, when specifying the columns for melt or .SDcols; in this context, non-standard evaluation is used internally to set cols to all data table column names, so please fix by removing cols argument", as.character(fun_uneval)) |
There was a problem hiding this comment.
I think this is a much more serious breaking change than #5247 -- just glancing at GitHub shows lots of people using cols=:
Even though I almost exclusively see it done with cols=names(x), such usage is now an error. We need to remove the cols= argument more gradually.
There was a problem hiding this comment.
Let's map out a deprecation plan, e.g.
1.16.0: warning() if cols is used for a subset of columns, message() if it's used for the full set of columns. The difference because the latter case should simply drop cols=, the former case can actually get different behavior.
1.17.0: Upgrade to error to provide cols=
1.18.0: Remove code related to cols=
We can consider an option to allow the old behavior to keep working as well, in which case we probably want to lengthen the deprecation cycle by one more release.
There was a problem hiding this comment.
another option is that we could continue to support user-provided cols and modify measure() to support that (would be possible I think if we make measure return character column names instead of integer column indices). However I think it would be better to do this warning/error, and encourage users to specify the right regex/pattern arg to patterns/measure. Thoughts?
There was a problem hiding this comment.
I don't have a strong prior here, though it does sound workable; do you think that would be useful and worth maintaining?
One thought is that it's sometimes clunky to jam everything into a pattern-based approach, e.g. it's not uncommon to have a vector of column names handy already, in which case just plugging it into cols= can be convenient as compared to turning that into a regex (esp if the column names might have special regex characters like ( { . etc). That said we haven't seen a request to this end.
closes #5063
Beta testing new measure() function revealed that users were confused about how to use cols arg.
Consensus from issue seems to be that docs for cols arg need to be clarified to indicate that users should NOT provide this argument.