posit-dev / posit-dev/air

Better Handling of Formatting Anonymous Functions that are Piped to?

Open
#412 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
446
Forks
32
Avg merge
16h 48m
Merged PRs (30d)
1

Description

Hello,

I was wondering if there air could better format the following piece of code?

correction_factor <- fitted.values(mod) |>
          {\(y_hat) (exp(y_hat) - 1)}() |>
          {\(y_hat_back_transformed) {
              lm(df$deaths ~ y_hat_back_transformed - 1)
            }}() |>
          {\(fitted_model) coef(fitted_model)}() |>
          {\(named_coef) unname(named_coef)}()

I'm running air 0.7.0 and it formats it this way, which I think is arguably harder to read because there's so much clutter separating the informative pieces of information

correction_factor <- fitted.values(mod) |>
  {
    \(y_hat) (exp(y_hat) - 1)
  }() |>
  {
    \(y_hat_back_transformed) {
      lm(df$deaths ~ y_hat_back_transformed - 1)
    }
  }() |>
  {
    \(fitted_model) coef(fitted_model)
  }() |>
  {
    \(named_coef) unname(named_coef)
  }()

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the R snippet in the issue and reproduce the current formatter output using air 0.7.0 or the repository's formatter entry point. Compare the requested pipe formatting with the existing output and define the desired result so the anonymous functions no longer add unnecessary visual clutter. Done means the formatter produces the improved layout consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.