Sweave, include sourced R-Function files

守給你的承諾、 提交于 2019-11-30 15:40:12

I guess life will be easier with the knitr package in this case. You can read a.R as a chunk label-a, and write it in c.Rnw:

<<read-code>>=
read_chunk('a.R', labels = 'label-a')
@
<<label-a>>
@

When you compile c.Rnw with library(knitr); knit('c.Rnw'), a.R will be included into the results (it is equivalent to copy & paste code into the chunk label-a). This is called code externalization in knitr.

\SweaveInput{} is not used to input R source code; you can only input Rnw documents.

I'm pretty sure you will get what you want if you use source("b.R", echo = TRUE) in a.R.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!