0

I'm relatively new to Knitr. I want to run a function just once, so that next time I don't have to evaluate it, because it would yield a different result. My MWE:

First time:

\documentclass{article}

\begin{document}

<<>>=
a<<-Sys.time()
@

<<>>=
a
@

\end{document}

Second time:

\documentclass{article}

\begin{document}

<<eval=FALSE>>=
a<-Sys.time()
@

<<>>=
a
@

\end{document}

I've tried using <<- so that the variable is stored in the global environment but it doesn't work.

Phil
  • 7,287
  • 3
  • 36
  • 66
paulgr
  • 89
  • 6
  • 3
    It looks like what you actually want to do is to use the same environment for two distinct sweave documents?! That is probably not going to happen, for good reasons, as described [here](https://stackoverflow.com/questions/34029611/how-to-use-objects-from-global-environment-in-rstudio-markdown). But nothing prevents you from storing the variables you want to use in multiple environments as .RData and load them in your sweave script. – dario Jul 04 '20 at 11:47
  • For the record, this was cross-posted at https://tex.stackexchange.com/q/552248/9128 – Yihui Xie Jul 04 '20 at 14:40

0 Answers0