我想从 RNW 文件中读取 RMD 文件中的块,它们都位于不同的文件夹中。我不能让它工作。似乎无法从 RMD 文件中读取块。read_chunk()
函数似乎只能从.R
文件中读取。但就我而言,我不能让它也能正常工作。
这是我的三个文件(在不同的文件夹中)和最后我的 RNW 文件的输出。任何想法为什么这不起作用?
“..\Folder_R\trial_r.R”
## @knitr r_chunk_1
14 + 17
cat("SUCCESS THIS IS R CHUNK 1!!!")
## @knitr r_chunk_2
plot(cars)
“..\Folder_html\trial_html.RMD”
---
title: "Untitled"
output: html_document
---
```{r html_chunk_1}
## @knitr html_chunk_1
cat("SUCCESS THIS IS HTML CHUNK 1!!!")
```
```{r html_chunk_2, echo=FALSE}
## @knitr html_chunk_2
plot(cars)
```
“..\Folder_latex\trial_latex.RNW”
\documentclass{article}
\begin{document}
\SweaveOpts{concordance=TRUE}
<<echo=FALSE>>=
library(knitr)
if (file.exists(file.path("..","Folder_html", "trial_html.Rmd")))
cat("`trial_html` File Exists!!\n\n")
read_chunk(file.path("..","Folder_html", "trial_html.Rmd"))
@
<<latex_chunk_1, echo=FALSE>>=
cat("This is LATEX Chunk!!")
@
<<latex_chunk_2, ref.label='html_chunk_1', echo=FALSE>>=
@
<<latex_chunk_3, echo=FALSE>>=
<<html_chunk_1>>
@
<<html_chunk_1, echo=FALSE>>=
@
<<latex_chunk_4, echo=FALSE>>=
if (file.exists(file.path("..","Folder_R", "trial_r.R")))
cat("`trial_r` File Exists!!\n\n")
read_chunk(file.path("..","Folder_R", "trial_r.R"))
@
<<latex_chunk_5, echo=FALSE>>=
<<r_chunk_1>>
@
<<r_chunk_2>>=
@
\end{document}
结果,我在 PDF 文件中看到的唯一内容是:
`trial_html` File Exists!!
This is LATEX Chunk!!
`trial_r` File Exists!!
我检查了以下来源THIS,这在某种程度上是我想要的,但无助于解决我的问题,这很有帮助,但我无法让它发挥作用。
我的编译警告信息是:
You can now run (pdf)latex on 'trial_latex.tex'
Warning messages:
1: In utils::Sweave("trial_latex.Rnw", encoding = "ISO8859-1") :
reference to unknown chunk 'html_chunk_1'
2: In utils::Sweave("trial_latex.Rnw", encoding = "ISO8859-1") :
reference to unknown chunk 'r_chunk_1'
Running pdflatex.exe on trial_latex.tex...completed