How can I define vars in one org-babel code block and use them in a second? This closely follows the tutorial section block-to-block variable passing linked in the first answer.
# file test.org
* try a session.
#+name: section1
#+begin_src R :results output both :session
x <- c(1:10)
y <- x^2
mat <- cbind(x,y)
mat
#+end_src
#this is outputted into the MWE after you press C-c C-c
#+RESULTS: section1
#+begin_example
x y
[1,] 1 1
[2,] 2 4
[3,] 3 9
[4,] 4 16
[5,] 5 25
[6,] 6 36
[7,] 7 49
[8,] 8 64
[9,] 9 81
[10,] 10 100
#+end_example
#+name: section2
#+BEGIN_SRC R :file example2.png :results graphics mat=section1
plot(mat)
#+END_SRC
#this is outputted into the MWE after you press C-c C-c
#+RESULTS: section2
here is a white box with the phrase
object 'mat' not found
when it is named section 2 the white box appears in the first results
#+begin_example section and the matrix of numbers disappears.