我想从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,THIS有点像我想要但却没有帮助解决我的问题,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