Skip to content

first function not working as fun.aggregate for dcast if fill argument is not provided #5390

Description

@iagogv3

I would expect I could do:

set.seed(1)
DT <- data.table(v1 = rep(1:2, each = 6),
                 v2 = rep(rep(1:3, 2), each = 2),
                 v3 = rep(1:2, 6),
                 v4 = rnorm(6))
dcast(DT, v1 + v2 ~ ., value.var = "v4", fun.aggregate = data.table::first)
Error: Aggregating function(s) should take vector inputs and return a single value (length=1). However, function(s) returns length!=1. This value will have to be used to fill any missing combinations, and therefore must be length=1. Either override by setting the 'fill' argument explicitly or modify your function to handle this case appropriately.

However I get an error instead of

dcast(DT, v1 + v2 ~ ., value.var = "v4", fun.aggregate = \(.).[1])
   v1 v2          .
1:  1  1 -0.6264538
2:  1  2 -0.8356286
3:  1  3  0.3295078
4:  2  1 -0.6264538
5:  2  2 -0.8356286
6:  2  3  0.3295078

Is it expected or a bug?

Activity

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