2011-08-29 12 views
5

Ho un problema con la larghezza dell'output da echo all'interno di sweave, ho una lista con una grande quantità di testo. Il problema è che la risposta ecologica di R scorre fuori dalla pagina all'interno del pdf. Ho provato a utilizzareCome controllare la larghezza dell'eco usando Sweave

<<>>= 
options(width=40) 
@ 

ma questo non ha cambiato nulla.

Un esempio: imposta l'elenco (non visualizzato in latex).

<<echo=FALSE>>= 
my_list <- list(example="Site location was fixed using a Silvia Navigator handheld GPS  in October 2003. Point of reference used was the station Bench Mark. If the bench mark location was remote from the site then the point of reference used was changed to the 0-1 metre gauge. Bench Mark location was then recorded as a separate entry in the Site History section [but not used as the site location].\r\nFor a Station location map and all digital photograph's of the station, river reach, and site details see H:\\hyd\\dat\\doc. For non digital photo's taken prior to October 2003 please see the relevant station file at Tumut office.") 
@ 

E mostrare la voce della lista.

<<>>= 
my_list 
@ 

C'è un modo che io possa arrivare a questo lavoro, senza dover rompere l'elenco con cat dichiarazioni.

+1

funziona perfettamente per me su un mac. puoi fornire maggiori dettagli sulla tua installazione e piattaforma in lattice – Ramnath

+1

su un Mac usando texshop 2.43. TeX versione 3.1415926 (TeX Live 2010). R 2.13.0. Funziona sulla mia macchina ma il testo scorre fuori dalla pagina nel pdf. –

+0

Cosa intendi con "la tua macchina"? –

risposta

3

È possibile utilizzare capture.output() per acquisire la rappresentazione stampata dell'elenco e quindi utilizzare writeLines() e strwrap() per visualizzare questa uscita, ben confezionata. Poiché capture.output() restituisce un vettore di stringhe contenenti la rappresentazione stampata dell'oggetto, possiamo applicare a ciascuna di esse una pagina sullo schermo/pagina, ma è stato eseguito il wrapping utilizzando strwrap(). Il vantaggio di questo approccio è che il risultato sembra come se fosse stato stampato da R. Ecco la soluzione:

writeLines(strwrap(capture.output(my_list))) 

che produce:

$example 
[1] "Site location was fixed using a Silvia Navigator 
handheld GPS in October 2003. Point of reference used 
was the station Bench Mark. If the bench mark location 
was remote from the site then the point of reference used 
was changed to the 0-1 metre gauge. Bench Mark location 
was then recorded as a separate entry in the Site History 
section [but not used as the site location].\r\nFor a 
Station location map and all digital photograph's of the 
station, river reach, and site details see 
H:\\hyd\\dat\\doc. For non digital photo's taken prior 
to October 2003 please see the relevant station file at 
Tumut office." 
+0

Grazie Gavin, lavora a meraviglia. –

1

Da un post 2010 al rhelp da Mark Schwartz:

cat(paste(strwrap(x, width = 70), collapse = "\\\\\n"), "\n") 
+0

Wow. Era 2 ore fa o 89 anni nel futuro? ;-) – Andrie

+1

Non sapevi che Mark era un Time Lord? –

Problemi correlati