styler (version 1.1.0)

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

Run this code
# NOT RUN {
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",
)
# }

Run the code above in your browser using DataCamp Workspace