Tabela de conteúdos

Rnw file

Rnw file

\documentclass{article}

\usepackage[noae,nogin]{Sweave}
\usepackage{tikz}

\begin{document}
\SweaveOpts{prefix.string=fig}

Example using \texttt{tikzDevice} with the default \textbf{Sweave}
driver (\texttt{RweaveLatex}).  First define a custom device:

<<results=hide>>=
library(pgfSweave)
tikz.Swd <- function(name, width, height, ...){
    require(tikzDevice)
    tikzDevice::tikz(file = paste(name, "tikz", sep = "."),
                 width = width, height = height)

}
@

Then use the device for plotting, but you have to include the figure manually.

<<myplot, fig=T, grdevice=tikz.Swd, include=F, width=4,height=4>>=
plot(1)
@
\input{fig-myplot.tikz}

\end{document}

R compilation session

walmes@galibi:~/Área de Trabalho/examples$ R
 
R version 2.12.1 (2010-12-16)
Copyright (C) 2010 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: i486-pc-linux-gnu (32-bit)
 
R é um software livre e vem sem GARANTIA ALGUMA.
Você pode redistribuí-lo sob certas circunstâncias.
Digite 'license()' ou 'licence()' para detalhes de distribuição.
 
R é um projeto colaborativo com muitos contribuidores.
Digite 'contributors()' para obter mais informações e
'citation()' para saber como citar o R ou pacotes do R em publicações.
 
Digite 'demo()' para demonstrações, 'help()' para o sistema on-line de ajuda,
ou 'help.start()' para abrir o sistema de ajuda em HTML no seu navegador.
Digite 'q()' para sair do R.
 
> Sweave("teste-tikz.Rnw")
Writing to file teste-tikz.tex
Processing code chunks ...
 1 : echo term hide
Loading required package: stashR
Loading required package: filehash
filehash: Simple key-value database (2.1-1 2010-10-04)
A Set of Tools for Administering SHared Repositories (0.3-3 2009-03-26)
Loading required package: highlight
Loading required package: tools
Loading required package: codetools
Loading required package: parser
Loading required package: Rcpp
Loading required package: optparse
Loading required package: getopt
Loading required package: formatR
tikzDevice: A Device for R Graphics Output in PGF/TikZ Format (v0.5.3)
Checking for a LaTeX compiler...
 
 
A working LaTeX compiler was found by checking:
	The PATH using the command pdflatex
 
Global option tikzLatex set to:
	/usr/bin/pdflatex
 
pdfTeX 3.1415926-1.40.10-2.2 (TeX Live 2009/Debian)
kpathsea version 5.0.0
 
 
pgfSweave: Using PGF Version 2.10
Erro em check(options) : invalid value for 'grdevice' : tikz.Swd
> sessionInfo()
R version 2.12.1 (2010-12-16)
Platform: i486-pc-linux-gnu (32-bit)
 
locale:
 [1] LC_CTYPE=pt_BR.utf8       LC_NUMERIC=C             
 [3] LC_TIME=pt_BR.utf8        LC_COLLATE=pt_BR.utf8    
 [5] LC_MONETARY=C             LC_MESSAGES=pt_BR.utf8   
 [7] LC_PAPER=pt_BR.utf8       LC_NAME=C                
 [9] LC_ADDRESS=C              LC_TELEPHONE=C           
[11] LC_MEASUREMENT=pt_BR.utf8 LC_IDENTIFICATION=C      
 
attached base packages:
[1] tools     stats     graphics  grDevices utils     datasets  methods  
[8] base     
 
other attached packages:
 [1] pgfSweave_1.2.1   tikzDevice_0.5.3  cacheSweave_0.4-5 formatR_0.2-1    
 [5] optparse_0.9.1    getopt_1.15       highlight_0.2-5   parser_0.0-13    
 [9] Rcpp_0.9.3        codetools_0.2-7   stashR_0.3-3      filehash_2.1-1   
 
loaded via a namespace (and not attached):
[1] digest_0.4.2
>

PGF installation procedure

File downloaded from http://sourceforge.net/projects/pgf/files/pgf/version%202.10/pgf_2.10.tds.zip/download. In a linux terminal I did (without errors)

$ sudo cp /home/walmes/Área\ de\ Trabalho/pgf_2.10.tds.zip /usr/local/share/texmf/
$ cd /usr/local/share/texmf/
$ sudo unzip pgf_2.10.tds.zip 
$ sudo texhash