Skip to content

Expressions using <- can overwrite active bindings in the data mask #6666

Description

@DavisVaughan

Seen in metacore

library(dplyr, warn.conflicts = FALSE)

foo <- tibble(
   x = c("CHG", "CHG", "CHG", "ABLFL", "ABLFL"),
   y = c("float", "integer", "float", "text", "text")
)
foo <- group_by(foo, x)

mutate(foo, y = {
   attr(y, "label") <- NULL
   y
})
#> Error in `mutate()`:
#> ℹ In argument: `y = { ... }`.
#> ℹ In group 2: `x = "CHG"`.
#> Caused by error:
#> ! `y` must be size 3 or 1, not 2.

#> Backtrace:
#>      ▆
#>   1. ├─dplyr::mutate(...)
#>   2. ├─dplyr:::mutate.data.frame(...) at dplyr/R/mutate.R:146:2
#>   3. │ └─dplyr:::mutate_cols(.data, dplyr_quosures(...), by) at dplyr/R/mutate.R:181:2
#>   4. │   ├─base::withCallingHandlers(...) at dplyr/R/mutate.R:268:2
#>   5. │   └─dplyr:::mutate_col(dots[[i]], data, mask, new_columns) at dplyr/R/mutate.R:273:6
#>   6. │     └─mask$eval_all_mutate(quo) at dplyr/R/mutate.R:380:8
#>   7. │       └─dplyr (local) eval() at dplyr/R/data-mask.R:69:6
#>   8. ├─dplyr:::dplyr_internal_error(...)
#>   9. │ └─rlang::abort(class = c(class, "dplyr:::internal_error"), dplyr_error_data = data) at dplyr/R/conditions.R:194:2
#>  10. │   └─rlang:::signal_abort(cnd, .file)
#>  11. │     └─base::signalCondition(cnd)
#>  12. └─dplyr (local) `<fn>`(`<dpl:::__>`)
#>  13.   └─rlang::abort(message, class = error_class, parent = parent, call = error_call) at dplyr/R/conditions.R:235:4

Created on 2023-01-26 with reprex v2.0.2.9000

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions