-
Notifications
You must be signed in to change notification settings - Fork 991
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
Programming with measure()
#4998
Comments
Hi I wrote the measure() function so I can help! > (measure.call <- as.call(list(
+ as.symbol("measure"),
+ as.symbol("group"),
+ as.symbol("id"),
+ sep="_")))
measure(group, id, sep = "_")
> (melt.call <- as.call(list(
+ as.symbol("melt"),
+ as.symbol("df"),
+ measure.vars=measure.call)))
melt(df, measure.vars = measure(group, id, sep = "_"))
> eval(melt.call)
group id value
1: x 1 1
2: x 2 2
3: y 1 1
4: y 2 2
> As this is a straightforward use of base R I think we don't need to add an argument to measure() that is character based (or some other solution). If that is ok with you @markfairbanks can you please close? |
Though this workaround works, I still think that some other solution should be implemented to make this easier. For a few reasons:
With those in mind here are a few proposals:
|
Hi @markfairbanks thanks for the suggestion, please try my new measurev function in measurev branch, #5022 |
well #5022 was recently merged into master so if the new measurev function works for you @markfairbanks can you please close this issue? |
Works great, thanks @tdhock 👍 library(data.table)
df <- data.table(
x_1 = 1,
x_2 = 2,
y_1 = 1,
y_2 = 2
)
my_melt <- function(data, fun_list) {
melt(
data,
measure.vars = measurev(fun.list = fun_list, sep = "_")
)
}
my_melt(df, list(group = NULL, id = NULL))
#> group id value
#> 1: x 1 1
#> 2: x 2 2
#> 3: y 1 1
#> 4: y 2 2 |
The new
measure()
has some very useful functionality, but the design being based around symbols makes creating custom functions with it difficult.Simple example:
Is there a possibility of adding an argument to
measure()
that is character based (or some other solution)?In the meantime is there a recommended workaround? I think I'm missing something simple, but I couldn't figure out a good way to do this.
The text was updated successfully, but these errors were encountered: