emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Babel and R: Call code block and output plot
@ 2015-07-27 16:17 Stefan Nobis
  2015-07-27 21:19 ` Andreas Leha
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Nobis @ 2015-07-27 16:17 UTC (permalink / raw)
  To: emacs-orgmode

Hi.

I'm playing a little bit with R code blocks in babel and calling them
in different parts of my document (e.g. showing output in the main
part and the code in the appendix).

With most code blocks (e.g. setting some variables or outputting a
LaTeX table with xtable) this works as expected (thanks to all working
on this; its really great).

Now I wanted to show a plot, but the associated code should also be
shown in the appendix. In this case CALL seems not to work (not plot
file is created or its empty).

Here is a small example of what I'm trying to achieve:

--8<---------------cut here---------------start------------->8---
#+TITLE: Plotting Test
#+OPTIONS: author:nil date:nil email:nil toc:nil
#+CREATOR: Emacs 24.5.1 (Org mode 8.2.10)
#+STARTUP: showall
#+PROPERTY: session *R*
#+PROPERTY: exports results

* Main Part

Here I want to show some plot:

#+CALL: myplot[:exports results]()

* Appendix

Here the code of the plot should be shown:

#+NAME: myplot
#+BEGIN_SRC R :results output graphics :exports code :file my-plot.pdf
hist(rnorm(50))
#+END_SRC
--8<---------------cut here---------------end--------------->8---

Any ideas what I'm doing wrong or how to better achieve my goal?

-- 
Until the next mail...,
Stefan.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Babel and R: Call code block and output plot
  2015-07-27 16:17 Babel and R: Call code block and output plot Stefan Nobis
@ 2015-07-27 21:19 ` Andreas Leha
  2015-07-28  7:44   ` Stefan Nobis
  0 siblings, 1 reply; 3+ messages in thread
From: Andreas Leha @ 2015-07-27 21:19 UTC (permalink / raw)
  To: emacs-orgmode

Hi Stefan,

Stefan Nobis <stefan-ml@snobis.de> writes:
> Hi.
>
> I'm playing a little bit with R code blocks in babel and calling them
> in different parts of my document (e.g. showing output in the main
> part and the code in the appendix).
>
> With most code blocks (e.g. setting some variables or outputting a
> LaTeX table with xtable) this works as expected (thanks to all working
> on this; its really great).
>
> Now I wanted to show a plot, but the associated code should also be
> shown in the appendix. In this case CALL seems not to work (not plot
> file is created or its empty).
>
> Here is a small example of what I'm trying to achieve:
>
> #+TITLE: Plotting Test
> #+OPTIONS: author:nil date:nil email:nil toc:nil
> #+CREATOR: Emacs 24.5.1 (Org mode 8.2.10)
> #+STARTUP: showall
> #+PROPERTY: session *R*
> #+PROPERTY: exports results
>
> * Main Part
>
> Here I want to show some plot:
>
> #+CALL: myplot[:exports results]()
>
> * Appendix
>
> Here the code of the plot should be shown:
>
> #+NAME: myplot
> #+BEGIN_SRC R :results output graphics :exports code :file my-plot.pdf
> hist(rnorm(50))
> #+END_SRC
>
> Any ideas what I'm doing wrong or how to better achieve my goal?


You still have to specify the format of the results of the #+CALL line, as in
#+CALL: myplot[:exports results]() :results file

BTW, I also think the 'output' in :results is spurious.

This work for me:


--8<---------------cut here---------------start------------->8---
#+TITLE: Plotting Test
#+OPTIONS: author:nil date:nil email:nil toc:nil
#+CREATOR: Emacs 24.5.1 (Org mode 8.2.10)
#+STARTUP: showall
#+PROPERTY: session *R*
#+PROPERTY: exports results

* Main Part

Here I want to show some plot:

#+CALL: myplot[:exports results]() :results file

#+results:
[[file:my-plot.pdf]]

* Appendix

Here the code of the plot should be shown:

#+NAME: myplot
#+BEGIN_SRC R :results graphics :exports code :file my-plot.pdf
hist(rnorm(50))
#+END_SRC
--8<---------------cut here---------------end--------------->8---

Best,
Andreas

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Babel and R: Call code block and output plot
  2015-07-27 21:19 ` Andreas Leha
@ 2015-07-28  7:44   ` Stefan Nobis
  0 siblings, 0 replies; 3+ messages in thread
From: Stefan Nobis @ 2015-07-28  7:44 UTC (permalink / raw)
  To: emacs-orgmode

Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:

> You still have to specify the format of the results of the #+CALL
> line, as in #+CALL: myplot[:exports results]() :results file

Works like a charm, thank you very much.

-- 
Until the next mail...,
Stefan.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-07-28  7:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-27 16:17 Babel and R: Call code block and output plot Stefan Nobis
2015-07-27 21:19 ` Andreas Leha
2015-07-28  7:44   ` Stefan Nobis

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).