From: Dan Davison <dandavison7@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: [babel] R: New handling of file output
Date: Tue, 21 Dec 2010 16:57:46 +0000 [thread overview]
Message-ID: <m1hbe7dpx1.fsf@94.196.16.201.threembb.co.uk> (raw)
In-Reply-To: m1y67jdsgw.fsf@94.196.16.201.threembb.co.uk
Dan Davison <dandavison7@gmail.com> writes:
> Please note the following changes to the way that org-babel handles
> file output. These may break existing org-babel files which use
> the :file header argument.
>
> :file <filename> should be understood as saying "write the result
> to <filename> and return a link to <filename>".
>
> This works for all languages. For graphics languages (e.g. ditaa, dot,
> gnuplot) there is no change in behavior: "result" in the above is the
> graphics, and a link to the image is placed in the org buffer. For
> general-purpose languages (e.g. emacs-lisp, python, R, ruby, shell),
> the "result" written to file is the normal org-babel result (string,
> number, table).
>
> This is a backwards-incompatible change for R, which was previously
> interpreting :file to mean "send graphics to file". I will send a
> separate email concerning R.
Previously R understood :file <filename> to mean "save graphics to
<filename>"[1]; now R behaves like other languages and sends the normal
org-babel result to file (string, number, table). To tell R to save
graphics[1] to file, use :results graphics.
Some examples:
Wrong!
#+begin_src R :file img.png
hist(rnorm(100))
"img.png is going to contain this string."
#+end_src
Use :results graphics save graphics:
#+begin_src R :file img.png :results graphics
hist(rnorm(100))
"But now img.png is going to contain graphics."
#+end_src
You may want to use `org-babel-default-header-args:R' to make this
more convenient:
#+begin_src emacs-lisp
(setq org-babel-default-header-args:R
'((:results . "graphics")))
#+end_src
Alternatively the :results graphics header can be set in a property
drawer for the subtree, or a #+babel: line, as usual.
Now this will do what was intended
#+begin_src R :file img.png
hist(rnorm(100))
#+end_src
Here is an example of saving something other than base graphics to file,
and returning a link to the file. Note that :file is not used, and the
filename must be returned. This could be used to save images created by
non-base graphics libraries:
#+begin_src R :results file :var file="savefile"
write.something.to.file <- function(f) cat("hello", file=f)
write.something.to.file(f=file)
file
#+end_src
Dan
* Footnotes
[1] This only works for "base" graphics.
>
> In order to return a file link from a src block without telling babel
> to save any results to that file, use :results <filename> and do not
> use :file. The code block can of course write arbitrary content to
> <filename>.
>
> Some examples:
>
> Save the output of ls -l as a .csv file (recall that :results value is
> the default):
>
> #+begin_src sh :file dirlisting.csv :sep ,
> ls -l
> #+end_src
>
> Send the text output of ls -l directly to file:
>
> #+begin_src sh :results output :file dirlisting.txt
> ls -l
> #+end_src
>
> Dan
>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
next prev parent reply other threads:[~2010-12-21 16:58 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-21 16:02 [babel] New handling of file output Dan Davison
2010-12-21 16:57 ` Dan Davison [this message]
2011-01-01 21:49 ` Re: [babel] R: " Thomas S. Dye
2011-01-01 22:58 ` Thomas S. Dye
2011-01-06 17:14 ` Dan Davison
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m1hbe7dpx1.fsf@94.196.16.201.threembb.co.uk \
--to=dandavison7@gmail.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.