在包中包含Rnw文件

在包中包含Rnw文件,r,package,knitr,R,Package,Knitr,我正在写一个包,这个包的唯一目的是创建报告。我正在使用knit从.Rnw文件生成报告。这一切都发生在包中的一个函数中。e、 g create_report <- function(data) { knit2pdf(from = "myreport.Rnw", to = "myreport.tex") # The Rnw in the knit2pdf function uses the data passed to this function } create_report回答这

我正在写一个包,这个包的唯一目的是创建报告。我正在使用
knit
从.Rnw文件生成报告。这一切都发生在包中的一个函数中。e、 g

create_report <- function(data) {
  knit2pdf(from = "myreport.Rnw", to = "myreport.tex")
  # The Rnw in the knit2pdf function uses the data passed to this function
}
create_report回答这个问题:

将.Rnw文件包括在
/pkgname/inst/latex
中,然后在构建包时,
/latex
文件夹将转到包的根级别。然后,您可以使用
system.file(“latex”,“mytemplate.Rnw”,package=“pkgname”)
提取.Rnw文件。WRE描述了在安装软件包时如何将inst/中的子文件夹复制到顶层。因此,您可以将模板(这就是我如何解释您的问题)放在inst/latex中,包用户可以使用
system.file
访问它们。好的,我现在仍在学习包开发,因此我将查看.Rproj.user。谁是雷伊?很抱歉我将尝试将它们放置在inst/latex中。我试着将它们放在inst中,但是在构建包之后system.file找不到它们…它们确实是模板,但是,正在编写R扩展名。如果你在写包裹的话,你真的应该读一下。我读过了。但我还是不明白。我试图使用
system.file()
,但它只返回
“”
。它在我的软件包中找不到inst文件夹(这是在我安装了它并且运行了
库之后。它一直在其他地方安装。安装的软件包不包括inst文件夹。我现在明白了!