Reputation: 347
I have a very simple knitr Rnw script. When I run it in RStudio, the Environment Pane shows that the global environment is empty although the script compiles into pdf correctly, and the variable is evaluated correctly.
\documentclass{article}
\begin{document}
<<settings, echo=FALSE>>=
library(knitr)
a<-1+10
@
The outcome is equal to \Sexpr{a}.
\end{document}
This worked fine always until recently. I wonder whether this has to do with some RStudio settings or knitr options. Variables in a regular R script show up fine in the environment pane. For more complex knitr projects, being able to look at the variables can make work much much easier.
Upvotes: 3
Views: 543
Reputation: 617
-To close Rstudio
-Go to "C:\Users\you_name_user\AppData\Local"
-Looking folder "Rstudio" and Delete this folder
-Rstart Rstudio
-This working, but will delete all packages that intall
Upvotes: 0
Reputation: 347
In the end, this is what worked for me. Instead of clicking on "Compile pdf" button in RStudio, I ran the following in the console:
knitr::knit2pdf("file.Rnw", envir = globalenv())
This had been recommended here: knitr: why does nothing appear in the "environment" panel when I compile my .Rnw file
Upvotes: 0
Reputation: 44907
Normally when you knit a document by clicking knit
in RStudio, it is run in a separate R process, and the variables are deleted when done. Your code chunks won't be able to see variables in your environment, and those variables won't get modified.
There are ways to run in your current process: run each chunk as code, or run rmarkdown::render("somefilename.Rmd")
in your main process. Then your document can see your current workspace and make modifications there.
For debugging, the 2nd approach is convenient, but for reproducibility of the final result, you should run the separate R process.
Upvotes: 2