emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Generating captions--is there a better way?
@ 2012-11-02  3:00 Michael Gauland
  2012-11-02  5:43 ` cberry
  0 siblings, 1 reply; 2+ messages in thread
From: Michael Gauland @ 2012-11-02  3:00 UTC (permalink / raw)
  To: emacs-orgmode

I use R to plot data, and like to include information about the plot in the
caption. I do this by combining two named SRC blocks--one for the image, and one
for the caption--and then put their #+RESULTS: together. The caption is the
tricky bit; I use R to print a string that starts with #+CAPTION:, shown in the
exmaple below. While this works, I've wondered if there is a more elegant way to
do this. How do others do this?

Kind Regards,
Mike Gauland

----- example -----

#+NAME: image
#+HEADER: :session
#+HEADER: :results graphics
#+HEADER: :exports results
#+HEADER: :file (org-babel-temp-file "./figure-" ".pdf")
#+BEGIN_SRC R
x <- rnorm(100)
hist(x)
#+END_SRC

#+NAME: caption
#+HEADER: :session
#+HEADER: :results raw
#+HEADER: :exports results
#+BEGIN_SRC R 
print(paste("#+CAPTION: The mean value is ",
            format(mean(x), digits=3),
	    ".", sep=""));
#+END_SRC

#+RESULTS: caption
#+RESULTS: image

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

* Re: Generating captions--is there a better way?
  2012-11-02  3:00 Generating captions--is there a better way? Michael Gauland
@ 2012-11-02  5:43 ` cberry
  0 siblings, 0 replies; 2+ messages in thread
From: cberry @ 2012-11-02  5:43 UTC (permalink / raw)
  To: emacs-orgmode

Michael Gauland <mikelygee@no8wireless.co.nz> writes:

> I use R to plot data, and like to include information about the plot in the
> caption. I do this by combining two named SRC blocks--one for the image, and one
> for the caption--and then put their #+RESULTS: together. The caption is the
> tricky bit; I use R to print a string that starts with #+CAPTION:, shown in the
> exmaple below. While this works, I've wondered if there is a more elegant way to
> do this. How do others do this?
>
[snip]

For something simple like this, I'd use:

,----
| #+PROPERTY: session *R*
| #+PROPERTY: results output
| 
| #+NAME: image
| #+HEADER: :results graphics
| #+HEADER: :exports results
| #+HEADER: :file (org-babel-temp-file "./figure-" ".pdf")
| #+BEGIN_SRC R
|   x <- rnorm(100)
|   caption.string <-
|     sprintf("The mean value is %.3f.\n",mean(x))
|   hist(x)
| #+END_SRC
| 
| 
| #+CAPTION: src_R[:results raw]{ cat(caption.string) }
| #+RESULTS: image
`----

For more complicated stuff I use ravel[1] to export as *.Rnw and then use
knitr on the result.



HTH,

Chuck

[1] see
https://github.com/chasberry/orgmode-accessories/blob/master/ravel-org.md

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

end of thread, other threads:[~2012-11-02  5:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-02  3:00 Generating captions--is there a better way? Michael Gauland
2012-11-02  5:43 ` cberry

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).