親コードのチャンク内で子の.Rmdスクリプトを '呼び出す'という問題が発生しています。親RマークダウンファイルのRチャンクは変数間でループし、親からの変数を使用する子Rマークダウンファイルを呼び出します。Knitrと親子のRコードのチャンク:子のチャンクがループ内の親の変数を認識できない
問題:親の変数を通して子値下げファイルになるだけループ外 Rコードチャンク値下げ中のラテックスコードとして。子のマークダウンファイルのRコードチャンク内にあるものは、ループ内の最初の変数のみを使用します。マークダウンの子供のラテックスコードが正常に動作する原因は何ですか?しかし、Rは親のループ内の変化する変数をフォローしませんか?
親ファイルの理論的な例:
```{r setup, include=FALSE}
library(knitr)
knitr::opts_chunk$set(cache=TRUE)
x <- as.vector(list(1:10))
```
## Now for the R chunk with loop on the child
```{r parent}
xD <- NULL
for (i in 1:length(x[[1]])){
out = NULL #reset the output of the loop to null, so duplicates aren't printed
xD[i] <- as.numeric(x[[1]][i])*2
currentValue <- xD[i]
out <- c(out, knit_expand(file = "test_child.Rmd"))
cat(knit(text=unlist(paste(out, collapse = '\n')), quiet=TRUE))
}
子ファイルtest_child.Rmd
の理論的な例:
The value outside a code chunk is `r currentValue` and
always updates with the variable in the parent's loop.
```{r childchunk}
print(paste0("But inside a code chunk, the value is", currentValue, "and
remains the same as the first value, regardless of the parent's loop
index.")) ```
を使用することができます
を使用してお勧めしたいです! – Guy