2009-09-10

Changing font size of R output in Lyx Sweave

Is there a simple way of reducing the size of the font of the R output in Lyx/Sweave? It should be simple, but I can't get anything to work. Placing\huge or \tiny in front of code chunk doesn't change the output.

My reply:
The trick is in what Sweave actually does. Sweave replaces the R code with the code and results, but as Sinput and Soutput environments, i.e.,
<<>>=
1 + 1
@
Becomes
\begin{Schunk}

\begin{Sinput}
> 1 + 1
\end{Sinput}

\begin{Soutput}
[1] 2
\end{Soutput}

\end{Schunk}
Therefore, I think you need to modify the Sinput and/or Soutput tex environments
defined in the Sweave.sty file. However, I have never done anything like that. I think there are some R packages on CRAN that did some of this things - I remember seeing green output etc.

4 comments:

Mario Pineda-Krch said...

Green output would be awesome - do you remember where you saw that?

Gorjanc Gregor said...

Take a look at

http://cran.r-project.org/web/packages/SweaveListingUtils/index.html

there is also some fine material at

http://biostat.mc.vanderbilt.edu/wiki/Main/SweaveConvert

http://biostat.mc.vanderbilt.edu/wiki/Main/SweaveLatex

http://biostat.mc.vanderbilt.edu/wiki/Main/SweaveTemplate

Yihui Xie said...

It's easy if you use a font size environment instead of a marco, e.g.

<<>>=
rnorm(20)
@

\begin{small}
<<>>=
rnorm(20)
@
\end{small}

\begin{huge}
<<>>=
rnorm(20)
@
\end{huge}

At least it works for me.

Gorjanc Gregor said...

Yihui, nice solution!