0

I learnt that there are two ways to nicely format R code in RStudio. One listed under Code -> Reformat code. The other is @yihui (formatR:tidy_r source code) which in current Version 0.99.893 of Rstudio, can be added as an addin. I noticed that, the in-built Reformat code formats the code to new line every time it encounters a comma ,( Imagine if you have a list of 10 parameters for some function, you will have 10 lines). However, I personally like @yihui tidy_r. So my questions are

1) How to make formatR as a default in Rstudio ?

2) Has anyone noticed errors while using formatR when run on Rshiny apps ? When I run this as an Addin on my shiny code, I get the error below...

Warning: Error in base::parse: <text>:81:1: unexpected symbol
80: invisible(".BeGiN_TiDy_IdEnTiFiEr_HaHaHa.HaHaHa_EnD_TiDy_IdEnTiFiEr")
81: invisible  

@yihui on his github page mentioned in 2012 that formatR is still not good at dealing with #. is this the case still ?

update as per comment

query = c(
       "26527521","26711930","26314551","26720421","26715198","26714964"           
     )

When the above input is formatted using Code -> Reformat code, results the output below

query = c("26527521",
          "26711930",
          "26314551",
          "26720421",
          "26715198",
          "26714964")
user5249203
  • 4,436
  • 1
  • 19
  • 45
  • I never encountered the situation you said where it adds a new line for every comma. What version of RStudio and under what specific situation does that happen? – Xiongbing Jin Apr 20 '16 at 19:33
  • updated the Q with the output – user5249203 Apr 20 '16 at 19:39
  • 1
    Thanks for the example. It seems that this happens when the line is long, but the line length where this happens is not fixed either... – Xiongbing Jin Apr 20 '16 at 19:54
  • 1
    BTW you can assign a keyboard shortcut to the `formatR` addin in Tools>Global options>Code>Editing>Modify keyboard shortcuts. And I encountered the same error when formatting Shiny apps. – Xiongbing Jin Apr 20 '16 at 20:17
  • Yeah. That is what bothering me as well. I would prefer `formatR`. But, it throws an error for shiny apps. And, I don't like the way `Code -> Reformat code` does the formatting. Basically, I have 2 options to neatly format R code, and neither works for my need. – user5249203 Apr 20 '16 at 20:25

0 Answers0