Skip to content

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

Open

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.

Activity

  1. venom1204 commented on May 27, 2026

    @venom1204
    Contributor

    hi @MichaelChirico @joshhwuu
    i have analyzed the issue and i plan to update the dcast.data.table to allow subset argument to behave like standard data.table indexing- the plan is to

    • Capture the subset expression without immediate evaluation to support bare logical statements.
    • maintaining the backward compatibility

    are there any suggestions or if this sounds good i will happy to proceed with the pr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions