镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

More consistency in handling matrices in j #6055

Open

Description

@MichaelChirico

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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions