From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Thomas S. Dye" Subject: Re: Re: [babel] R: New handling of file output Date: Sat, 1 Jan 2011 11:49:05 -1000 Message-ID: <29120182-1E50-4935-A34B-0EC1E55F4F6C@tsdye.com> References: Mime-Version: 1.0 (Apple Message framework v936) Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Return-path: Received: from [140.186.70.92] (port=59738 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PZ9K4-000728-Jm for emacs-orgmode@gnu.org; Sat, 01 Jan 2011 16:49:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PZ9K3-0004CR-8I for emacs-orgmode@gnu.org; Sat, 01 Jan 2011 16:49:12 -0500 Received: from oproxy3-pub.bluehost.com ([69.89.21.8]:50873) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1PZ9K2-0004BG-W8 for emacs-orgmode@gnu.org; Sat, 01 Jan 2011 16:49:11 -0500 In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Dan Davison Cc: emacs-orgmode@gnu.org Aloha all, Should :results graphic be documented in the :results header argument section of the Org-mode manual, or in the R-specific documentation? All the best, Tom On Dec 21, 2010, at 6:57 AM, Dan Davison wrote: > Dan Davison 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 should be understood as saying "write the result >> to and return a link to ". >> >> 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 to mean "save graphics to > "[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 and do not >> use :file. The code block can of course write arbitrary content to >> . >> >> 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 > > > _______________________________________________ > 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