More consistency in handling matrices in j

Open
#6,055 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
r
Domain
data

Research direction

Start by reviewing the behavior described in #6054 and the existing handling in as.data.table.list() and as.data.table(). Compare the grouped and ungrouped matrix examples, first deciding the intended recycling and column-expansion rules; done means the behavior is consistent and the listed cases are covered by tests.

Written by the indexing model from the issue text.

Description

consistency

Follow-up to #783 / #6054.

Outside grouping, matrices in j are auto-converted by as.data.table.list() so that entries are OK as long as the dimensions look "right" in the same way that as.data.table() works:

DT=data.table(a=rep(1:2, 3), b=1:6)

DT[, .(cbind(b))] # OK, 1 column output
DT[, .(cbind(b, b))] # OK, 2 columns output
DT[, .(b, cbind(b, b))] # OK, 3 columns output
DT[, .(b[1L], cbind(b, b))] # OK, 3 columns output, length-1 recycling rules
# OK-ish, 3 columns output with warning about uneven recycling, but could be error?
DT[, .(b[-1L], cbind(b, b))]

Note that the case without .(...) in grouping is not interesting, since the return value is always "plain" like what you'd get with with(), i.e. the output need not be a data.table.

Inside grouping, as of #6054, we have this behavior:

DT[, cbind(b), by=a] # OK, 2 columns output
# !! inconsistent with ungrouped case: 2 columns, equivalent to `DT[, .(c(b,b)), by=a]`
#   IMO consistency would say this should be DT[, .(b, b), by=a]
DT[, cbind(b, b), by=a]
DT[, .(cbind(b)), by=a] # OK, 2 columns output
# error as of #6054, but for consistency could be DT[, .(b,b), by=a]
DT[, .(cbind(b, b)), by=a]
# error, IMO this implies the last un-grouped case should also be an error -- only singletons are recycled.
DT[, .(1, 1:2, 1:3), by=a]
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.