Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set graphical parameters (par()) and structure options (strOptions()) in a knitr document?

Tags:

r

knitr

I am working on a knitr-sweave document and have found that global R options like

par(lwd=3)

and

strOptions(strict.width='cut')

do not take effect in later code chunks. I can specify these options as arguments each time I plot() or str(), so it's not a huge problem. I'm just wondering if anyone has any insight into this. Should I be caching the code chunk where I set these options? I call some libraries in early code chunks and set variables in others and they all seem to be accessible "globally" (i.e. in later code chunks).

like image 682
rcorty Avatar asked May 03 '14 01:05

rcorty


People also ask

How do you set graphical parameters in R?

The format is par(optionname=value, optionname=value, ...) A second way to specify graphical parameters is by providing the optionname=value pairs directly to a high level plotting function. In this case, the options are only in effect for that specific graph.

How do I use parameters in Rmarkdown?

Parameters in an R Markdown document are very simple to use. In the yaml header (the section at the top of the markdown document), you just have to add a couple new lines for your parameters to hardcode them in. Once they're coded in, they will be available in the params object for use in the rest of the analysis.


1 Answers

I believe I can help you with setting strOptions globally. Just set your str options as a list under options, like this:

options(str = list(strict.width = "cut"))
like image 179
Waldir Leoncio Avatar answered Nov 02 '22 21:11

Waldir Leoncio