How to write a function that formats spacing in R?


I am trying to write a function that would format code.

I found the following interesting Stack Overflow Post that goes into how to format certain tokens/operators, but I am trying to specifically format spacing. How do you reference spacing around parentheses to create a new line? In the Stack Overflow post, when printing the as.list(, spaces are not visible, and it is unclear how to format them to me.

Basically trying to add some formatting on top of the in-built formatting or packages that exist. If anyone could explain how to do this that would be very appreciated. In a nutshell, I'd like to understand it. How do you specify when to make a new line? Similar to the formatR package or the in built code formatter (Code -> Reformat Code drop down).

Thank you.

# starting code
data <-
  data %>%
  group_by(region, category) 

# formatted
data <-
  data %>%

The code to formatR is available here :
formatR/tidy.R at master ยท yihui/formatR (

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.