-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Odd behaviour of melt()
when using the cols
argument in measure()
#5063
Comments
I also struggle to understand the
In contrast to @uwe, I manage to select the
However, when selecting the two "y" columns, only the "var" and "ix" columns are correct. I would expect columns "y_1" and "y_2" to be "x_1" and "x_2" with their corresponding values, and the "value" column to have values from "y_1" and "y_2".
What am I missing here? A big thanks to everyone involved in developing |
Thank you for testing new features before they are released! The cols argument to measure() has indeed not been handled properly. |
Check you brackets. |
Sorry @tlapak for me being sloppy. Deleted. |
I wrote > d = data.table(x_1 = 1, x_2 = 2, y_1 = 3, y_2 = 4)
> melt(d, measure.vars = measure(ix, pattern = "x_(.*)"))
y_1 y_2 ix value
<num> <num> <char> <num>
1: 3 4 1 1
2: 3 4 2 2 |
I think this is a problem with documentation. The OP was able to get the result they wanted by specifying the pattern arg without the cols arg. So would it fix the issue to change the documentation of the cols arg to something like the following? "cols: a character vector that is automatically provided, with all of the column names of the data table input to melt. The user should NOT provide this argument; to specify the columns to be measured, use the pattern argument." |
Thank you for the detailed explanation, @tdhock ! My impression was that the This would help in cases where So, if |
yes let's remove cols arg if possible, or at least clarify in the documentation that it should not be specified by the user. |
We can make |
that is an interesting idea @MichaelChirico but I don't think that will work. (we will get error even when user does not specify cols, because it is filled in automatically -- not missing) |
Hello. Where can we find the documentation and examples on how to use measure() ? Thanks. |
?measure and search for measure( in datatable-reshape vignette (in github master) |
Going back to the example in your original post, if you run that code using #5115, then you will get the informative error message below, instead of the warning and wrong result: > melt(df, measure.vars = measure(var, year, cols = cols, pattern = "([BC]XO)X(\\d{4})"))
Erreur : user should not provide cols argument to measure |
measure()
is a great enhancement tomelt()
- thanks a lot for this!However, while experimenting with the new
measure()
function when trying to find an answer for this question on SO I came across an odd behaviour ofmelt()
when thecols
argument is used withmeasure()
:#
Minimal reproducible example
This gives the expected result (note that the
AXO
columns intentionally have be left out of the reshape):Now, when I include
cols
in the call tomeasure()
I get an unexpected and obviously wrong result and a warning:
The documentation says on the
pattern
argument:Perhaps, I have completely misunderstood the meaning of the
cols
argument. Unfortunately, I have found no example of the proper use ofcols
neither in the documentation ofmeasure()
nor in the reshape vignette.Even stranger, when using a function to create the character vector of column names in the call, I get an error message right away:
#
Output of sessionInfo()
The text was updated successfully, but these errors were encountered: