I'm currently working on a Windows computer, and having some issues interaction with knitr and Rcpp.
My code works fine when I run it on Rstudio, but when I try to use knitr to create the html file, I get the error:
Creating the html file works when I remove that line, so it seems it's not a problem in neither Rcpp or knitr packages.
On another note, I never used the sourceCPP function in the code, but cppFunction(variable with C code as string).
As required, I created a simplified example, script "cppcode.R" below:
library(Rcpp)
library(RcppArmadillo)
ccode = "
NumericMatrix rand_mat(NumericVector dim){
IntegerVector v = seq_len(2) - 1;
int N = dim[0];
int M = dim[1];
NumericMatrix Y(N,M);
for(int i=0;i<N;i++){
for(int j=0;j<M;j++){
Y(i,j) = sample(v,1,true)[0];
}
}
return Y;
}
"
cppFunction(code=ccode,depends="RcppArmadillo")
Then the Rmd file:
#This is an example
```{r}
source("cppcode.R")
rand_mat(c(3,3))
```
Works if just run the lines on Rstudio, but gives me the same error when I press the knit button.