Skip to content

Add warning/documentation of assignment pipe incompatibility with base pipe #278

@gvelasq

Description

@gvelasq

Thank you for magrittr, it remains one of my favorite R packages. This issue aims to follow-up on #269 and #253 (comment). In those issues, it was mentioned that building a compatibility layer between %<>% and |> is out of scope for magrittr.

For those who prefer to use %<>% (carefully) for its conciseness despite prior style guidance, especially those who have switched their default pipe operator to |> or are migrating codebases from %>% to |>, this may lead to silent errors like the one below:

# 1. setup ----
library(dplyr, warn.conflicts = FALSE)
library(magrittr)

# 2. data ----
a <- tibble(mtcars)

# 3. console output ----
# the immediately-provided console output shows the expected computation
a %<>%
  select(cyl) |>
  mutate(cyl2 = cyl) |>
  filter(cyl2 == 6)
#> # A tibble: 7 × 2
#>     cyl  cyl2
#>   <dbl> <dbl>
#> 1     6     6
#> 2     6     6
#> 3     6     6
#> 4     6     6
#> 5     6     6
#> 6     6     6
#> 7     6     6

# 4. assigned value ----
# the assigned value of `a` stores only the pipeline steps before the first |>
a
#> # A tibble: 32 × 1
#>      cyl
#>    <dbl>
#>  1     6
#>  2     6
#>  3     4
#>  4     6
#>  5     8
#>  6     6
#>  7     8
#>  8     4
#>  9     4
#> 10     6
#> # ℹ 22 more rows

Would the maintainers consider either of the following to avoid silent errors?

  1. Build in a warning message when %<>% is used together with |> in a pipeline. This would only be possible if the presence of |> can be detected.
  2. Add a note in the documentation for %<>% that it is incompatible / should not be used with |>.

Thank you for considering.

Created on 2025-08-01 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