8
votes

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).

1
par is only supposed to affect the current graphical device. I am a bit surprised that strOptions doesn't have a durable effect.IRTFM
I get that par is for current devices, but why doesn't something like op <- par(pch = '$', col = green) work in a subsequent chunks by calling op again?rawr
@rawr I feel the same as @BondedDust. For par(), it is because knitr opens a new device for each code chunk. Perhaps I should record par() throughout the session to make the settings persistent. Personally I often use a chunk hook to set par(), e.g. github.com/yihui/knitr/blob/…Yihui Xie

1 Answers

1
votes

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"))