Skip to content

dcast's subset argument could behave more like base::subset than reshape2::dcast #4325

Description

@MichaelChirico

Being more used to base::subset, I was surprised when the following didn't work:

x = data.table(a = rep(1:5, 3), b = rep(1:3, each = 5), v = rnorm(15))
dcast(x, a ~ b, value.var = 'v', subset = a > 1)

Error in which(eval(subset, data, parent.frame())) :
argument to 'which' is not logical

That's because dcast.data.table is modelled after reshape2::dcast, where the following is expected:

x = data.table(a = rep(1:5, 3), b = rep(1:3, each = 5), v = rnorm(15))
# works
dcast(x, a ~ b, value.var = 'v', subset = .(a > 1))

Am I missing something? Can't we just drop the .()?

We could also support both -- should be easy to peel off .() if we see it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions