>> >> As I understand this particular case, the OP is using a hash not to mark >> a result as up to date, but rather to mark a side effect (loading data >> into R) as having taken place. I think this is a misuse of a cache. > > It depends on whether one looks at a cache as “a place to store results” > or “a way to conditionally rerun code blocks only when they change”, I > suppose. I guess you hold with the former; I think the latter is a > useful conceptual extension. Knitr (http://yihui.name/knitr/) is a very > useful literate programming tool for R, and it supports “caching” code > with side-effects using clever means. I don’t think org should do all > the tricks knitr does, but it would be useful to be able to > conditionally reexecute code with no results/with side effects. >
Could something like the following work? Removing ":results none" and adding something small as the returned result which may easily be parsed and placed in the buffer w/o problem. #+begin_src R :cache yes # code to perform side effect x <- 'side effect' 'done' #+end_src #+RESULTS[9f4e5b4b07e93c680ab37fc4ba1f75e1bfc0ee0a]: : done > >> >> What if the R process restarts? The hash would still be valid, but the >> side effects have been lost. > > This is also an issue if the external data files have changed, the RNG > seed is no longer the same, etc. In such cases, the user has to be > clever. But the same is true of any cached code that is not a pure > function. > > In practice, if the R process is restarted the “variable not found” > errors quickly become apparent, and reloading the data is a simple C-u > C-c C-c away. > > (That being said, including the PID of the R process in the results > hash, to the effect that the code would be rerun in the case you > mention, might not be a bad idea. But that is a separate discussion.) This does not need special built in support, e.g., #+name: R-pid #+begin_src sh :var R="/usr/lib64/R/bin/exec/R" ps auxwww|grep "$R"|grep -v 'grep'|awk '{print $2}' #+end_src #+begin_src R :cache yes :var pid=R-pid # code to perform side effect x <- 'side effect' 'done' #+end_src #+RESULTS[da16f09882a6295815db51247592b77c80ed0056]: : done Best, -- Eric Schulte http://cs.unm.edu/~eschulte