[R] Sweave function

Eik Vettorazzi E.Vettorazzi at uke.uni-hamburg.de
Tue Jul 6 12:02:41 CEST 2010


Hi,
I don't know why, but your resulting table is not latex but html. (e.g.
& is not recognized in latex).

NA.string is an argument for print.xtable, not for xtable itself and is
case sensitive.

So

<<echo=F,results=tex>>=
report2=lapply(report1, function(x) {
print(xtable(x),NA.string="-")})
@

should work.
hth.


Am 06.07.2010 11:13, schrieb n.vialma at libero.it:
> Dear list,
> I'm trying to generate a latex Document in which there are a lot of tables. I'm using the Sweave function in the package utils, but I'm having a lot of problems with the format. This is my code:
> \documentclass[a4paper]{amsbook}
> \title{Schema di bilancio}
> \begin{document}
> \maketitle
> <<echo=F,results=hide>>=
> report=Bilanci
> mynames<-names(report)
> mynames[mynames=="AA01"]<-"Immobilizzazioni tecniche nette"
> mynames[mynames=="AA01I"]<-"Immobilizzazioni imm. nette"
> mynames[mynames=="AA01M"]<-"Immobilizzazioni mat. nette"
> mynames[mynames=="AA02"]<-"Partecipazioni e crediti fin."
> mynames[mynames=="AA02B"]<-"Attivita' fin. a breve"
> mynames[mynames=="AA02L"]<-"Immobilizzazioni finan."
> mynames[mynames=="AA03"]<-"Magazzino"
> mynames[mynames=="AA04"]<-"Crediti commerciali"
> mynames[mynames=="AA05"]<-"Liquidita'"
> mynames[mynames=="AA06"]<-"Altre attivita'"
> mynames[mynames=="AA07"]<-"Tot attivita'"
> mynames[mynames=="AL01"]<-"Capitale netto"
> mynames[mynames=="AL02"]<-"Fondo tfr"
> mynames[mynames=="AL03"]<-"Altri fondi"
> mynames[mynames=="AL04"]<-"Debiti commerciali"
> mynames[mynames=="AL04A"]<-"Anticipi di clienti"
> mynames[mynames=="AL04B"]<-"Debiti vs fornitori"
> mynames[mynames=="AL05"]<-"Debiti fin. tot."
> mynames[mynames=="AL05B"]<-"Debiti fin. a breve"
> mynames[mynames=="AL05L"]<-"Debiti fin. a medio/lungo"
> mynames[mynames=="AL99"]<-"Altre passivita'"
> mynames[mynames=="AL06"]<-"Tot passivita'"
> mynames[mynames=="EC01"]<-"Ricavi netti"
> mynames[mynames=="EC02"]<-"Produzione int. capitalizzate"
> mynames[mynames=="EC03"]="Variazione scorte prod finiti"
> mynames[mynames=="EC04"]<-"Acquisti"
> mynames[mynames=="EC05"]<-"Variazioni scorte mat. prime"
> mynames[mynames=="EC06"]<-"Costi per servizi e god. di beni terzi"
> mynames[mynames=="EC07"]<-"Costo del lavoro tot"
> mynames[mynames=="EC08"]<-"Ammortamenti e accantonamenti"
> mynames[mynames=="EC08A"]<-"Ammortamenti"
> mynames[mynames=="EC08B"]<-"Accantonamenti e utilizzi di riserve"
> mynames[mynames=="EC09"]<-"Oneri fin."
> mynames[mynames=="EC10"]<-"Proventi fin."
> mynames[mynames=="EC11"]<-"Ricavi diversi netti"
> mynames[mynames=="EC11A"]<-"Altri ricavi netti ord"
> mynames[mynames=="EC11C"]<-"Contributi in conto esercizio"
> mynames[mynames=="EC12"]<-"Proventi straord. netti"
> mynames[mynames=="EC13"]<-"Imposte"
> mynames[mynames=="EC14"]<-"Utile netto rettificato"
> mynames[mynames=="EC15"]<-"Rettifiche"
> mynames[mynames=="EC16"]<-"Utile dell'esercizio"
> names(report)<-mynames
> report=split(report,report$CFISCALE)
> report1=lapply(report,function(x){
> t(x)})
> @
> <<echo=F,results=tex>>=
> report2=lapply(report1, function(x) {
> print(xtable(x,na.string="-"))})
> @
> \end{document}
>
>
> Even if I put the code referring to the title, in my pdf document I don't get it and I don't know why. Secondly I get the following error message:(\end occurred when \ifnum on line 2150 was incomplete)
> the results of this error is that I loose a lot of tables. Instead of having 500 tables I have just 250 tables. Another problem is that the format is not what I would like to get, my tables appear at the center of the page and I would like to put them at the left (the result is that my table are cut), and I don't know how to do that, I've tried to put in the xtable function the option table.placement="H" but it seems that it doesn't work.An example of what I get by using the split function and then the xtable function is:
> & 49 & 48 & 47 \\ 
>   \hline
> CFISCALE & 5060157 & 5060157 & 5060157 \\ 
>   RAGSOCB & GIUSEPPE TARENZI S.R.L. & GIUSEPPE TARENZI S.R.L. & GIUSEPPE TARENZI S.R.L. \\ 
>   ANNO & 2005 & 2006 & 2007 \\ 
>   Ricavi netti &  77 &  98 & 124 \\ 
>   Produzione int. capitalizzate & 0 & 0 & 0 \\ 
>   Variazione scorte prod finiti & 2059 & 2105 & 2120 \\ 
>   Acquisti & 1542 & 1564 & 1576 \\ 
>   Costi per servizi e god. di beni terzi & 122 & 135 & 121 \\ 
>   Costo del lavoro tot & 273 & 281 & 301 \\ 
>   Ammortamenti e accantonamenti & 11 &  5 &  7 \\ 
>   Ammortamenti & 9.9 & 4.5 & 6.3 \\ 
>   Accantonamenti e utilizzi di riserve & 1.1 & 0.5 & 0.7 \\ 
>   Oneri fin. & 38 & 42 & 35 \\ 
>   Proventi fin. & 1 & 0 & 1 \\ 
>   Ricavi diversi netti &   0 & -13 & -33 \\ 
>   Altri ricavi netti ord &   0 & -13 & -33 \\ 
>   Contributi in conto esercizio & 0 & 0 & 0 \\ 
>   Proventi straord. netti & 1 & 0 & 0 \\ 
>   Imposte & 73 & 78 & 80 \\ 
>   Utile netto rettificato & 79 & 85 & 92 \\ 
>   Utile dell'esercizio & 79 & 85 & 92 \\ 
>   Immobilizzazioni tecniche nette & 269 & 267 & 274 \\ 
>   Partecipazioni e crediti fin. & 0 & 3 & 0 \\ 
>   Magazzino & 592 & 623 & 656 \\ 
>   Crediti commerciali & 17.56393 & 28.15887 & 26.14891 \\ 
>   Liquidita' &  14 &  & 177 \\ 
>   Altre attivita' &  -892.564 &  & -1133.149 \\ 
>   Tot attivita' & 0.000000000 & 0.005924951 & 0.000000000 \\ 
>   Immobilizzazioni imm. nette & 53.8 & 53.4 & 54.8 \\ 
>   Immobilizzazioni mat. nette & 215.2 & 213.6 & 219.2 \\ 
>   Attivita' fin. a breve & 0.0 & 1.5 & 0.0 \\ 
>   Immobilizzazioni finan. & 0.0 & 1.5 & 0.0 \\ 
>   Capitale netto & 0.000000000 & 0.002773298 & 0.000000000 \\ 
>   Fondo tfr & -558.4306 & -666.3115 & -533.6478 \\ 
>   Altri fondi & 0 & 0 & 0 \\ 
>   Debiti commerciali & 558.4306 & 666.3146 & 533.6478 \\ 
>   Debiti fin. tot. & 0.000000e+00 & 2.340336e-05 & 0.000000e+00 \\ 
>   Tot passivita' & 0.000000000 & 0.005924951 & 0.000000000 \\ 
>   Anticipi di clienti & 0 & 0 & 0 \\ 
>   Debiti vs fornitori & 558.4306 & 666.3146 & 533.6478 \\ 
>   Debiti fin. a breve & 0.000000e+00 & 1.170168e-05 & 0.000000e+00 \\ 
>   Debiti fin. a medio/lungo & 0.000000e+00 & 1.170168e-05 & 0.000000e+00 \\ 
>   Altre passivita' & 0 & 0 & 0 \\
> I would like to not see the first line, namely & 49 & 48 & 47 \\, in my table wich is the result of the split function applied to a list. Secondly I don't want the repetion of the variables Cfiscale and Ragsocb, so my result should be:
>
>
>    \hline
>  CFISCALE & 5060157  \\ 
>    RAGSOCB & GIUSEPPE TARENZI S.R.L.\\
> but I don't know I to solve it in a list.
> Someone knows how to solve these problems!
> Thanks for your attention!
>
>
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>   

-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790



More information about the R-help mailing list