0

I'm writing my thesis in RStudio with knitr and want to go back and reformat my .Rnw files so that no line exceeds 80 characters.

I've noticed this answer for scite but I'm not sure how to make this work in my situation.

Are there are R tools (or command line tools) to do this kind of job?

Community
  • 1
  • 1
StevieP
  • 1,569
  • 12
  • 23
  • wouldn't doing that programmatically insert line breaks where they might break your code or mess things up? in the middle of a variable name or character string for instance? – rawr May 11 '14 at 20:43
  • Technically, a robust solution should find the closest bit of white space to the 80 character mark and break from there. Either way, breaking the code is a risk I'm willing to take. – StevieP May 11 '14 at 21:13
  • "if all you have is a hammer, ..." here is a solution using a text editor http://superuser.com/questions/464456/sublime-text-2-insert-breaks-to-match-current-wrapping – rawr May 11 '14 at 21:32
  • You might find this paper interesting, too http://bloodjournal.hematologylibrary.org/content/103/2/746.full – rawr May 11 '14 at 21:34
  • I don't think my use of robust was gratuitous but I can see where you're coming from. ;-) – StevieP May 11 '14 at 22:43
  • have you tried running the R source through [formatR](http://cran.r-project.org/web/packages/formatR)? There is an option for line char length limit: `tidy.source(source="clipboard", width.cutoff=80)` – hrbrmstr May 12 '14 at 13:58
  • it doesn't need to be on the clipboard, too :-) not sure it will do anything for non-R source code, tho. – hrbrmstr May 12 '14 at 14:01
  • I just came across the formatR package and came back here to suggest it as well @StevieP – rawr May 24 '14 at 02:43

0 Answers0