Skip to content

cube support for patterns with .SDcols #7354

@al-obrien

Description

@al-obrien

I recently tried to use patterns within the .SDcols input to cube() and was faced with an error: Error in patterns ("value"): Pattern(s) not found: [[value]]

This was surprising considering I am able to perform this operation in almost any other use of .SDcols. This may be more of a feature request for consistency across the interface.

Example

Based off the help page...

n = 24L
set.seed(25)
DT <- data.table(
    color = sample(c("green","yellow","red"), n, TRUE),
    year = as.Date(sample(paste0(2011:2015,"-01-01"), n, TRUE)),
    status = as.factor(sample(c("removed","active","inactive","archived"), n, TRUE)),
    amount = sample(1:5, n, TRUE),
    value = sample(c(3, 3.5, 2.5, 2), n, TRUE)
)

# Works as per example
cube(DT, j = lapply(.SD, sum), by = c("color","year","status"), id=TRUE, .SDcols="value")


# Fails with "Error in patterns ("value"): Pattern(s) not found: [[value]]#
cube(DT, j = lapply(.SD, sum), by = c("color","year","status"), id=TRUE, .SDcols=patterns("value"))

Output of sessionInfo()

Image

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions