emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [babel] New handling of file output
@ 2010-12-21 16:02 Dan Davison
  2010-12-21 16:57 ` [babel] R: " Dan Davison
  0 siblings, 1 reply; 5+ messages in thread
From: Dan Davison @ 2010-12-21 16:02 UTC (permalink / raw)
  To: emacs-orgmode

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.

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

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

* Re: [babel] R: New handling of file output
  2010-12-21 16:02 [babel] New handling of file output Dan Davison
@ 2010-12-21 16:57 ` Dan Davison
  2011-01-01 21:49   ` Thomas S. Dye
  2011-01-01 22:58   ` Thomas S. Dye
  0 siblings, 2 replies; 5+ messages in thread
From: Dan Davison @ 2010-12-21 16:57 UTC (permalink / raw)
  To: emacs-orgmode

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

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

* Re: Re: [babel] R: New handling of file output
  2010-12-21 16:57 ` [babel] R: " Dan Davison
@ 2011-01-01 21:49   ` Thomas S. Dye
  2011-01-01 22:58   ` Thomas S. Dye
  1 sibling, 0 replies; 5+ messages in thread
From: Thomas S. Dye @ 2011-01-01 21:49 UTC (permalink / raw)
  To: Dan Davison; +Cc: emacs-orgmode

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 <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
>
>
> _______________________________________________
> 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

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

* Re: Re: [babel] R: New handling of file output
  2010-12-21 16:57 ` [babel] R: " Dan Davison
  2011-01-01 21:49   ` Thomas S. Dye
@ 2011-01-01 22:58   ` Thomas S. Dye
  2011-01-06 17:14     ` Dan Davison
  1 sibling, 1 reply; 5+ messages in thread
From: Thomas S. Dye @ 2011-01-01 22:58 UTC (permalink / raw)
  To: Dan Davison; +Cc: emacs-orgmode

Aloha all,

Here is an example of the new handling of file output with an R source  
code block that doesn't use "base" graphics:

#+srcname: r-edge-angle-histogram
#+begin_src R :results output graphics :var x=whole-adzes :file r/ 
adze_edge_angle.png :width 400 :height 300
   library(ggplot2)
   adze.edge.angle <- ggplot(x, aes(edge_angle))
   adze.edge.angle + geom_histogram(aes(y=..density..)) +
   geom_density(weight=2) + xlab("Measured cutting edge angle  
(degrees)")
#+end_src

#+results:
[[file:r/adze_edge_angle.png]]

Previously, the source line was:
#+begin_src R :results output :var x=whole-adzes :file r/ 
adze_edge_angle.png :width 400 :height 300

The only change was to append graphics to :results output.

All the best,
Tom

On Dec 21, 2010, at 6:57 AM, Dan Davison wrote:

> 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
>
>
> _______________________________________________
> 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

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

* Re: [babel] R: New handling of file output
  2011-01-01 22:58   ` Thomas S. Dye
@ 2011-01-06 17:14     ` Dan Davison
  0 siblings, 0 replies; 5+ messages in thread
From: Dan Davison @ 2011-01-06 17:14 UTC (permalink / raw)
  To: emacs-orgmode

"Thomas S. Dye" <tsd@tsdye.com> writes:

> Aloha all,
>
> Here is an example of the new handling of file output with an R source  
> code block that doesn't use "base" graphics:
>
> #+srcname: r-edge-angle-histogram
> #+begin_src R :results output graphics :var x=whole-adzes :file r/ 
> adze_edge_angle.png :width 400 :height 300
>    library(ggplot2)
>    adze.edge.angle <- ggplot(x, aes(edge_angle))
>    adze.edge.angle + geom_histogram(aes(y=..density..)) +
>    geom_density(weight=2) + xlab("Measured cutting edge angle  
> (degrees)")
> #+end_src

I was initially a bit baffled by this example. If anyone else is curious
as to why, when graphics are generated by ggplot2, :results output is
required in addition to :results graphics, please see Erik Iverson's
original post on producing grid-based (e.g. lattice, ggplot2) R graphics
with org-babel (bearing in mind of course that the header arg syntax has
changed as per this thread).

http://article.gmane.org/gmane.emacs.orgmode/26082

Dan

>
> #+results:
> [[file:r/adze_edge_angle.png]]
>
> Previously, the source line was:
> #+begin_src R :results output :var x=whole-adzes :file r/ 
> adze_edge_angle.png :width 400 :height 300
>
> The only change was to append graphics to :results output.
>
> All the best,
> Tom
>
> On Dec 21, 2010, at 6:57 AM, Dan Davison wrote:
>
>> 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
>>
>>
>> _______________________________________________
>> 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

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

end of thread, other threads:[~2011-01-06 17:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-21 16:02 [babel] New handling of file output Dan Davison
2010-12-21 16:57 ` [babel] R: " Dan Davison
2011-01-01 21:49   ` Thomas S. Dye
2011-01-01 22:58   ` Thomas S. Dye
2011-01-06 17:14     ` Dan Davison

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