如何使用 Sweave 控制回波宽度
我对 sweave 中 echo 的输出宽度有疑问,我有一个包含大量文本的列表。问题是来自 R 的回显响应超出了 pdf 页面的范围。我尝试过使用
<<>>=
options(width=40)
@
但这并没有改变任何东西。
一个例子:设置列表(不显示在乳胶中)。
<<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
语句分解列表。
I have a problem with the width of the output from echo within sweave, I have a list with a large amount of text. The problem is the echo response from R runs off the page within the pdf. I have tried using
<<>>=
options(width=40)
@
but this has not changed anything.
An example: Set up the list (not showing 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.")
@
And show the entry of the list.
<<>>=
my_list
@
Is there any way that I can get this to work without having to break up the list with cat
statements.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 capture.output() 捕获列表的打印表示,然后使用 writeLines() 和 strwrap() 来显示此内容输出,包装精美。由于 capture.output() 返回一个包含对象打印表示的字符串向量,我们可以将它们中的每一个捕获到屏幕/页面,但使用 strwrap() 进行包装。这种方法的好处是结果看起来就像是由 R 打印的。解决方案如下:
它会产生:
You can use
capture.output()
to capture the printed representation of the list and then usewriteLines()
andstrwrap()
to display this output, nicely wrapped. Ascapture.output()
returns a vector of strings containing the printed representation of the object, we can cat each of them to the screen/page but wrapped usingstrwrap()
. The benefit of this approach is that the result looks like it was printed by R. Here's the solution:which produces:
来自 Mark Schwartz 2010 年发布到 rhelp 的文章:
From a 2010 posting to rhelp by Mark Schwartz: