Skip to content

Across gives unclear error when function returns incorrect length output #7785

@billdenney

Description

@billdenney

In the example below, the function gives a 2-length result for a 1-length input. (My real case to generate this error involved changing levels for a factor, and the return value for the function was the levels and not the factor variable.)

Can the error message please be improved from

#> ! Can't compute column `A`.
#> Caused by error in `dplyr_internal_error()`:

To something indicating that the return value's length is incorrect?

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
d_test <- data.frame(A = 1)
give_two <- function(x) {
  1:2
}
mutate(d_test, across("A", give_two))
#> Error in `mutate()`:
#> ℹ In argument: `across("A", give_two)`.
#> Caused by error in `across()`:
#> ! Can't compute column `A`.
#> Caused by error in `dplyr_internal_error()`:

Created on 2025-12-21 with reprex v2.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions