5

スウィーブ内のエコーからの出力の幅に問題があります。大量のテキストを含むリストがあります。問題は、R からのエコー応答が pdf 内のページから外れることです。使ってみました

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

しかし、これは何も変わっていません。

例: リストを設定します (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.")
@

そして、リストのエントリを表示します。

<<>>=
my_list
@

リストをcatステートメントで分割することなく、これを機能させる方法はありますか。

4

2 に答える 2

3

を使用capture.output()してリストの印刷された表現をキャプチャし、 と を使用writeLines()strwrap()てこの出力を適切にラップして表示できます。ascapture.output()は、オブジェクトの印刷された表現を含む文字列のベクトルを返します。それぞれを画面/ページに cat できますが、 を使用してラップされstrwrap()ます。このアプローチの利点は、結果がR によって出力されたように見えることです。解決策は次のとおりです。

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

これは以下を生成します:

$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."
于 2011-08-29T20:47:45.027 に答える
1

Mark Schwartz による 2010 年の rhelp への投稿から:

cat(paste(strwrap(x, width = 70), collapse = "\\\\\n"), "\n")
于 2011-08-29T21:48:48.710 に答える