2011-08-29 16 views
5

Mam problem z szerokością wyjścia z echa w grze Sweave, mam listę z dużą ilością tekstu. Problem polega na tym, że odpowiedź echa z R przebiega poza stronę w pliku pdf. Podjęto próbę użyciaJak kontrolować szerokość echa za pomocą Sweave

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

ale to się nie zmieniło.

Przykład: Ustaw listę (nie wyświetla się w lateksie).

<<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.") 
@ 

Pokaż listę pozycji.

<<>>= 
my_list 
@ 

Czy jest jakiś sposób, że mogę uzyskać to do pracy bez konieczności rozbijania listy z cat wypowiedzi.

+1

działa idealnie dla mnie na komputerze Mac. czy możesz podać więcej szczegółów na temat instalacji i platformy lateksowej? – Ramnath

+1

Na komputerze Mac z użyciem texshop 2.43. Wersja TeX 3.1415926 (TeX Live 2010). R 2.13.0. Działa na moim komputerze, ale tekst kończy się na stronie w pliku pdf. –

+0

Co masz na myśli "Twoja maszyna"? –

Odpowiedz

3

Możesz użyć capture.output(), aby przechwycić drukowaną reprezentację listy, a następnie użyć writeLines() i , aby wyświetlić to wyjście, ładnie zapakowane. Ponieważ capture.output() zwraca wektor ciągów znaków zawierających drukowaną reprezentację obiektu, możemy umieścić każdego z nich na ekranie/stronie, ale owinąć przy użyciu strwrap(). Zaletą tego podejścia jest to, że wynik wygląda jakby było wydrukowane przez R. Oto rozwiązanie:

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

która produkuje:

$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

Dzięki Gavin, działa uczta. –

1

Od 2010 delegowania do rhelp Mark Schwartz:

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

Wow. Czy to było 2 godziny temu, czy 89 lat w przyszłości? ;-) – Andrie

+1

Nie wiedziałeś, że Mark był Władcą Czasu? –

Powiązane problemy