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

Open
#4,325 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
55/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Quiet
Tech stack
r
Domain
data

Research direction

Start by reproducing the two dcast examples in the issue, then inspect the dcast.data.table entry point and how it evaluates subset. Done means subset = a > 1 works alongside subset = .(a > 1) without changing the existing behavior.

Written by the indexing model from the issue text.

Description

reshape

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.

Dominant language
R
Stars
3.9k
Forks
1.1k
Avg merge
14h 4m
Merged PRs (30d)
4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Rdatatable/data.table

All issues in Rdatatable/data.table

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.