On 3/2/2012 12:59 PM, Christophe Pouzat wrote:
Matthew,
I think that you're wrongly expecting babel's cache header argument to
behave like the argument of the same name in Sweave code chunks. Babel
will cache, in your case, the value of your code block evaluation and
there is none in your first code block, therefore nothing gets cached by
babel, try that instead:
#+name: my-random-vector
#+begin_src R :session :cache yes
rnorm(100)
#+end_src
#+headers: :var x=my-random-vector
#+headers: :results graphics :exports results :file hist.png
#+begin_src R :session :cache yes
hist(x)
#+end_src
Does it work better? In that case you don't even need a session.
Christophe
Christophe - thanks for the suggestion. I haven't messed around much
with variables passed between code blocks. When I try this, R tells me
that 'x' must be numeric. When I query x in the R buffer, x is a
data.frame. So the second code block reads x in as a data.frame instead
of a numeric vector.
For most purposes this would be OK (since a data.frame is the most usual
outcome), but I'm reluctant to use this approach -- I'd like all of the
variable passing to be in the R session. Intuitively this seems
simpler, less error prone, and more conducive to tangling later. (Of
course, I could be totally wrong - since I haven't really tried that
approach).
M
--
~~~~~~~~~~~~~~~~~~~~~~~~~~
Matthew Landis, Ph.D.
Research Scientist
ISciences, LLC
61 Main St. Suite 200
Burlington VT 05401
802.864.2999
www.isciences.com
~~~~~~~~~~~~~~~~~~~~~~~~~~