Setting the line length in R
Asked Answered
P

2

5

Google R style guide suggests line length of maximum 80 characters. I was wondering how do I set the line length in R. In stata this is done as:

set linesize 80
Peristyle answered 15/1, 2013 at 22:51 Comment(0)
E
8

Is:

options()$width

what you want?

You can set it like:

options(width=80)
Earleanearleen answered 15/1, 2013 at 22:53 Comment(2)
Note this sets the width of (most of) the output. Line width of input will be based on whatever editor/IDE you are using.Tarrel
Note that if you use the RStudio IDE, this option seems to be dynamically modified each time you resize the IDE window.Visional
L
0

If you are using R inside RStudio and/or within an rmarkdown (.Rmd) document, you can temporarily set the line length to format possible text output files.

An example:

ops <- options()
options(width=80) # Ensure that the printout formatting remains constant
writeLines(capture.output(sessionInfo()),
           file.path("your/folders/sessInfo.txt"))
options(ops); rm(ops)

When working within RStudio, the console line length is adjusted dynamically, and thus must be set within a chunk to affect the output.

Loiretcher answered 12/7 at 7:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.