token_is_on_aligned_line {styler}R Documentation

Check if tokens are aligned

Description

If all tokens are aligned, TRUE is returned, otherwise FALSE. The function only checks for alignment of function calls. This can be recycled conveniently later if needed as a vector with length > 1.

Usage

token_is_on_aligned_line(pd_flat)

Arguments

pd_flat

A flat parse table.

Details

Multiple lines are called aligned if the following conditions hold for all but the first line of the expression:

Because of the last requirement, this function is very expensive to run. For this reason, the following approach is taken:

Examples

library("magrittr")
withr::with_options(
  list(styler.cache_name = NULL), # temporarily deactivate cache
  {
    transformers <- tidyverse_style()
    pd_nested <- compute_parse_data_nested(c(
      "call(",
      "  ab = 1L,",
      "  a  = 2",
      ")"
    )) %>%
      styler:::post_visit(transformers$initialize)
    nest <- pd_nested$child[[1L]]
    styler:::token_is_on_aligned_line(nest)
  }
)

[Package styler version 1.9.1 Index]