Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

relocate_eq_assign

Relocate the expressions containing the token EQ_ASSIGN within the nested parse table


Description

Although syntactically identical, utils::getParseData() does not produce the same hierarchy of the parse table (parent and id relationship) for <- and = (See 'Examples'). This is considered to be a bug and causes problems because the nested parse table constructed with compute_parse_data_nested() is not consistent if EQ_ASSIGN occurs in the expression to style. In particular, EQ_ASSIGN and the tokens to its left and right are located too high up in the hierarchy of the nested parse data. Hence, this function wraps the sub-expression into an expression, similar to wrap_expr_in_curly(). Since wrap_expr_in_curly() is called from within a visitor (and relocate_eq_assign() not), we need to wrap the the implementation relocate_eq_assign_nest() that operates on nests into a visitor call.

Usage

relocate_eq_assign(pd)

Arguments

pd

A parse table.

Examples

styler:::get_parse_data("a <- b <- 3")
styler:::get_parse_data("a  = b = 3")
styler:::get_parse_data(
  "x = 5
  if(x >= 5)
  y = TRUE else
  y = FALSE",
)
styler:::get_parse_data(
  "x <- 5
  if(x >= 5)
  y <- TRUE else
  y <- FALSE",
)

styler

Non-Invasive Pretty Printing of R Code

v1.4.1
MIT + file LICENSE
Authors
Kirill Müller [aut], Lorenz Walthert [cre, aut]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.