Skip to main content
corrected answer
Source Link

I tried to follow your example, both using the :PROPERTIES: drawer like your mysql example and with (same) named code-blocks. Neither is working to call an R variable in the second code-block.

* my.org

#+TITLE:TEST
#+AUTHOR:Benyomin
#+STARTUP: inlineimages

*** tryThis aMWE realgraphs session.with Namea bothvariable code-blocksfrom thean same.
#+name:earlier section1code-block
#+begin_src R :results output :session
 
# name the list_var "why"
print("Generate ten numbers")
whynums <- (seq(1,10)
why
print("Then randomize them and print those.")
# make it a bit random
zee <- why * runif(1, .1, 2.3)
zee   # give a simple text output
#plot(zee)  # plot zee  ooops,  save that for the next code blocknums
#+end_src 

#+RESULTS:
: [1] "Generate ten numbers"
:  [1]  1  2  3  4  5  6  7  8  9 10
: [1] "Then randomize them and print those."
:  [1]  1.209789  2.419579  3.629368  4.839157  6.048946  7.258736  8.468525
:  [8]  9.678314 10.888103 12.097893

** but will this part work?
This is also text that is in the org doc. It is part of the MWE. It is not a bullet point and separates the 2 code-blocks.  It is part of debugging to see if it was part of the problem of variables not persisting between code blocks.

#+name: section1
#+BEGIN_SRC R :file example2example.png :results graphics
print("Plot a variable created in a different code block.")
plot(zee)
print("result is white box with object 'zee' not found"nums)
#+END_SRC

This is what happens after you hit C-c C-c both code blocks to execute the R code. MWE after code execution

I tried to follow your example, both using the :PROPERTIES: drawer like your mysql example and with (same) named code-blocks. Neither is working to call an R variable in the second code-block.

#+TITLE:TEST
#+AUTHOR:Benyomin
#+STARTUP: inlineimages

* try a real session. Name both code-blocks the same.
#+name: section1
#+begin_src R :results output :session
 
# name the list_var "why"
print("Generate ten numbers")
why <- seq(1,10)
why
print("Then randomize them and print those.")
# make it a bit random
zee <- why * runif(1, .1, 2.3)
zee   # give a simple text output
#plot(zee)  # plot zee  ooops,  save that for the next code block
#+end_src 

#+RESULTS:
: [1] "Generate ten numbers"
:  [1]  1  2  3  4  5  6  7  8  9 10
: [1] "Then randomize them and print those."
:  [1]  1.209789  2.419579  3.629368  4.839157  6.048946  7.258736  8.468525
:  [8]  9.678314 10.888103 12.097893

** but will this part work?
This is also text that is in the org doc. It is part of the MWE. It is not a bullet point and separates the 2 code-blocks.  It is part of debugging to see if it was part of the problem of variables not persisting between code blocks.

#+name: section1
#+BEGIN_SRC R :file example2.png :results graphics
print("Plot a variable created in a different code block.")
plot(zee)
print("result is white box with object 'zee' not found")
#+END_SRC
* my.org

#+TITLE:TEST
#+AUTHOR:Benyomin
#+STARTUP: inlineimages

** This MWE graphs with a variable from an earlier code-block
#+begin_src R :results output :session
nums <- (seq(1,10))
nums
#+end_src

#+BEGIN_SRC R :file example.png :results graphics
plot(nums)
#+END_SRC

This is what happens after you hit C-c C-c both code blocks to execute the R code. MWE after code execution

changed format back to single .org doc
Source Link

I tried to follow your example, both using the :PROPERTIES: drawer like your mysql example and with (same) named code-blocks. Neither is working to call an R variable in the second code-block.

#+TITLE:TEST
#+AUTHOR:Benyomin
#+STARTUP: inlineimages

* try a real session. Name both code-blocks the same.
#+name: section1
#+begin_src R :results output :session

# name the list_var "why"
print("Generate ten numbers")
why <- seq(1,10)
why
print("Then randomize them and print those.")
# make it a bit random
zee <- why * runif(1, .1, 2.3)
zee   # give a simple text output
#plot(zee)  # plot zee  ooops,  save that for the next code block
#+end_src 

#+RESULTS:
: [1] "Generate ten numbers"
:  [1]  1  2  3  4  5  6  7  8  9 10
: [1] "Then randomize them and print those."
:  [1]  1.209789  2.419579  3.629368  4.839157  6.048946  7.258736  8.468525
:  [8]  9.678314 10.888103 12.097893

** but will this part work?

Here is a long description of 3 paragraphs stuck in the middle of some code. Can the second piece of code refer to things done in the earlier code block? That's something very important for me.

This is also text that is in the org doc. It is part of the MWE. It is not a bullet point and separates the 2 code-blocks.  It is part of debugging to see if it was part of the problem of variables not persisting between code blocks.

#+name: section1
#+BEGIN_SRC R :file example2.png :results graphics
print("Plot a variable created in a different code block.")
plot(zee)
print("result is white box with object 'zee' not found")
#+END_SRC

I tried to follow your example, both using the :PROPERTIES: drawer like your mysql example and with (same) named code-blocks. Neither is working to call an R variable in the second code-block.

#+TITLE:TEST
#+AUTHOR:Benyomin
#+STARTUP: inlineimages

* try a real session. Name both code-blocks the same.
#+name: section1
#+begin_src R :results output :session

# name the list_var "why"
print("Generate ten numbers")
why <- seq(1,10)
why
print("Then randomize them and print those.")
# make it a bit random
zee <- why * runif(1, .1, 2.3)
zee   # give a simple text output
#plot(zee)  # plot zee  ooops,  save that for the next code block
#+end_src 

#+RESULTS:
: [1] "Generate ten numbers"
:  [1]  1  2  3  4  5  6  7  8  9 10
: [1] "Then randomize them and print those."
:  [1]  1.209789  2.419579  3.629368  4.839157  6.048946  7.258736  8.468525
:  [8]  9.678314 10.888103 12.097893

** but will this part work?

Here is a long description of 3 paragraphs stuck in the middle of some code. Can the second piece of code refer to things done in the earlier code block? That's something very important for me.

#+name: section1
#+BEGIN_SRC R :file example2.png :results graphics
print("Plot a variable created in a different code block.")
plot(zee)
print("result is white box with object 'zee' not found")
#+END_SRC

I tried to follow your example, both using the :PROPERTIES: drawer like your mysql example and with (same) named code-blocks. Neither is working to call an R variable in the second code-block.

#+TITLE:TEST
#+AUTHOR:Benyomin
#+STARTUP: inlineimages

* try a real session. Name both code-blocks the same.
#+name: section1
#+begin_src R :results output :session

# name the list_var "why"
print("Generate ten numbers")
why <- seq(1,10)
why
print("Then randomize them and print those.")
# make it a bit random
zee <- why * runif(1, .1, 2.3)
zee   # give a simple text output
#plot(zee)  # plot zee  ooops,  save that for the next code block
#+end_src 

#+RESULTS:
: [1] "Generate ten numbers"
:  [1]  1  2  3  4  5  6  7  8  9 10
: [1] "Then randomize them and print those."
:  [1]  1.209789  2.419579  3.629368  4.839157  6.048946  7.258736  8.468525
:  [8]  9.678314 10.888103 12.097893

** but will this part work?
This is also text that is in the org doc. It is part of the MWE. It is not a bullet point and separates the 2 code-blocks.  It is part of debugging to see if it was part of the problem of variables not persisting between code blocks.

#+name: section1
#+BEGIN_SRC R :file example2.png :results graphics
print("Plot a variable created in a different code block.")
plot(zee)
print("result is white box with object 'zee' not found")
#+END_SRC
formatting
Source Link
Emacs User
  • 5.7k
  • 19
  • 48

I tried to follow your example, both using the :PROPERTIES: drawer like your mysql example and with (same) named code-blocks. Neither is working to call an R variable in the second code-block.

#+TITLE:TEST
#+AUTHOR:Benyomin
#+STARTUP: inlineimages

* try a real session. Name both code-blocks the same.
#+name: section1
#+begin_src R :results output :session

# name the list_var "why"
print("Generate ten numbers")
why <- seq(1,10)
why
print("Then randomize them and print those.")
# make it a bit random
zee <- why * runif(1, .1, 2.3)
zee   # give a simple text output
#plot(zee)  # plot zee  ooops,  save that for the next code block
#+end_src 

#+RESULTS:
: [1] "Generate ten numbers"
:  [1]  1  2  3  4  5  6  7  8  9 10
: [1] "Then randomize them and print those."
:  [1]  1.209789  2.419579  3.629368  4.839157  6.048946  7.258736  8.468525
:  [8]  9.678314 10.888103 12.097893

** but will this part work?
Here is a long description of 3 paragraphs stuck in the middle of some code.  Can the second piece of code refer to things done in the earlier code block?  That's something very important for me.

Here is a long description of 3 paragraphs stuck in the middle of some code. Can the second piece of code refer to things done in the earlier code block? That's something very important for me.

#+name: section1
#+BEGIN_SRC R :file example2.png :results graphics
print("Plot a variable created in a different code block.")
plot(zee)
print("result is white box with object 'zee' not found")
#+END_SRC

I tried to follow your example, both using the :PROPERTIES: drawer like your mysql example and with (same) named code-blocks. Neither is working to call an R variable in the second code-block.

#+TITLE:TEST
#+AUTHOR:Benyomin
#+STARTUP: inlineimages

* try a real session. Name both code-blocks the same.
#+name: section1
#+begin_src R :results output :session

# name the list_var "why"
print("Generate ten numbers")
why <- seq(1,10)
why
print("Then randomize them and print those.")
# make it a bit random
zee <- why * runif(1, .1, 2.3)
zee   # give a simple text output
#plot(zee)  # plot zee  ooops,  save that for the next code block
#+end_src 

#+RESULTS:
: [1] "Generate ten numbers"
:  [1]  1  2  3  4  5  6  7  8  9 10
: [1] "Then randomize them and print those."
:  [1]  1.209789  2.419579  3.629368  4.839157  6.048946  7.258736  8.468525
:  [8]  9.678314 10.888103 12.097893

** but will this part work?
Here is a long description of 3 paragraphs stuck in the middle of some code.  Can the second piece of code refer to things done in the earlier code block?  That's something very important for me.
#+name: section1
#+BEGIN_SRC R :file example2.png :results graphics
print("Plot a variable created in a different code block.")
plot(zee)
print("result is white box with object 'zee' not found")
#+END_SRC

I tried to follow your example, both using the :PROPERTIES: drawer like your mysql example and with (same) named code-blocks. Neither is working to call an R variable in the second code-block.

#+TITLE:TEST
#+AUTHOR:Benyomin
#+STARTUP: inlineimages

* try a real session. Name both code-blocks the same.
#+name: section1
#+begin_src R :results output :session

# name the list_var "why"
print("Generate ten numbers")
why <- seq(1,10)
why
print("Then randomize them and print those.")
# make it a bit random
zee <- why * runif(1, .1, 2.3)
zee   # give a simple text output
#plot(zee)  # plot zee  ooops,  save that for the next code block
#+end_src 

#+RESULTS:
: [1] "Generate ten numbers"
:  [1]  1  2  3  4  5  6  7  8  9 10
: [1] "Then randomize them and print those."
:  [1]  1.209789  2.419579  3.629368  4.839157  6.048946  7.258736  8.468525
:  [8]  9.678314 10.888103 12.097893

** but will this part work?

Here is a long description of 3 paragraphs stuck in the middle of some code. Can the second piece of code refer to things done in the earlier code block? That's something very important for me.

#+name: section1
#+BEGIN_SRC R :file example2.png :results graphics
print("Plot a variable created in a different code block.")
plot(zee)
print("result is white box with object 'zee' not found")
#+END_SRC
added names
Source Link
Loading
Source Link
Loading