[R] Sweave

Marc Schwartz marc_schwartz at comcast.net
Tue Nov 18 20:28:50 CET 2008

on 11/18/2008 10:31 AM Yiguo Sun wrote:
> Dear All,
> I have both R 2.80 and Scientific Workplace 5.5 installed on my
> computer.
> I copied the following commands from HTML help provided by R:
> testfile <- system.file("Sweave", "Sweave-test-1.Rnw", package =
> "utils") Sweave(testfile)
> I then compile Sweave-test-1.tex file using Scientific Workplace 5.5.
> Apparently, Scienfic Workplace 5.5 does not recognize the *.tex file
> created by R. Could anyone show me how to do it correctly. Thank you
> very much for your help.
> Regards,
> Yiguo

I have not used SW, so may have to defer to others on details. However,
presuming that it either uses an installed TeX system or its own to
process the .tex file, there was a change in the default behavior in the
RweaveLatex driver for 2.8.0, as noted in the NEWS file:

    o	The default for 'stylepath' in Sweave's (default) RweaveLatex
	driver is now FALSE rather than TRUE if
	SWEAVE_STYLEPATH_DEFAULT is unset : see ?RweaveLatex.
	To support this, tools::texi2dvi adds the R 'texmf' directory
	to the input search path.

and as per ?RweaveLatex:

The LaTeX file generated needs to contain \usepackage{Sweave}, and if
this is not present in the Sweave source file, it is inserted by the
RweaveLatex driver. If stylepath = TRUE, a hard-coded path to the file
‘Sweave.sty’ in the R installation is set in place of Sweave. The
hard-coded path makes the TeX file less portable, but avoids the problem
of installing the current version of ‘Sweave.sty’ to some place in your
TeX input path. However, TeX may not be able to process the hard-coded
path if it contains spaces (as it often will under Windows) or TeX
special characters.

The default in R prior to 2.7.0 was stylepath = TRUE. It is now taken
from the environment variable SWEAVE_STYLEPATH_DEFAULT, or is FALSE it
that is unset or empty. If set, it should be exactly TRUE or FALSE: any
other values are taken as FALSE.

The result of these changes is that in your resultant .tex file, you
will likely observe the following line:


rather than something like (on Linux) prior to 2.8.0 with the defaults:


In the latter case, the full path to Sweave.sty is specified so the TeX
processor can find it.

You can use the approaches outlined in the help file above to address this.


Marc Schwartz

More information about the R-help mailing list