我一直在使用knitr,R markdown和pandoc为我将在秋季教授的课程创建投影演示/讲座.我编写了一个简短的R脚本来自动化该过程(类似于`make'文件),其中包括:
.Rmd文件;.tex文件;.tex文件;一切似乎都很好,有一个例外(迄今为止).只有当我直接调用编织功能时,我才有一个似乎"编织好"的讲座.当我尝试使用我的make函数编织.Rmd文件时,某些R对象无法识别.我在下面列举了一个简短的例子来说明问题:
我创建了一个名为"test.Rmd"的文件,其中包含一个代码块(如下所示):
## Simulation
```{r test, comment=NA, message=FALSE, warning=FALSE}
library(mosaic)
obs<-c(25, 22, 30, 40) # Number of observations in each category
Ais<-c(0.34, 0.101, 0.104, 0.455) # Total Accreage (NUll proportions)
e.count<-Ais*117 # Expected Counts
test.stat<-sum((obs-e.count)^2/(e.count)) #Test statistic = 43.6
rand.dist<-do(1000)*{
# Randomization Distribution
new.dat<-sample(1:4, replace=TRUE, size=117, prob=Ais) # Sample with Prob = Null pi's
new.obs<-tally(~new.dat) # Simulated counts
chi.sq<-sum((new.obs-e.count)^2/e.count) # Simulated test statistic
} …Run Code Online (Sandbox Code Playgroud)