emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* sbe with :file header arg?
@ 2011-10-07 17:49 Myles English
  2011-10-07 18:22 ` Eric Schulte
  0 siblings, 1 reply; 3+ messages in thread
From: Myles English @ 2011-10-07 17:49 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

I think I have one case of strange behaviour and one feature request, if it
isn't already possible.

I would like to make one plot per row of a table.  This is useful because the
contents of the row may be parameters in an R session, and a link to the
resulting plot can be put in the last cell of each row.

The following source block makes a plot:

#+source: plotTest
#+headers: :var A="A" :var B="B" :var C="C"
#+begin_src R :file nofile.png :results graphics :session b
  plot( 1,1, ylab=A, xlab=B)
text(0.8,0.8,C)
#+end_src

#+results: plotTest
[[file:nofile.png]]

and the source block may be called using this table:

#+TBLNAME: testtbl
 | "5" | "X" | "Y" | nofile.png |
 |   7 | P   | "Q" | nofile.png |
#+TBLFM: $4='(sbe plotTest (A $1)(B $2)(C $3))

executing that shows up the strange behaviour because the R interpreter
contains:

> > png(filename="nofile.png")
> A <- "5"
> B <- "X"
> C <- "Y"
>   plot( 1,1, ylab=A, xlab=B)
> text(0.8,0.8,C)
> dev.off()
null device 
          1 
> > png(filename="nofile.png")
> A <- 7
> B <- "/home/myles/org/org/nofile.png"       <------  STRANGE, NO?
> C <- "Q"
>   plot( 1,1, ylab=A, xlab=B)
> text(0.8,0.8,C)
> dev.off()
null device 
          1

Now the feature request; would it be possible to pass a :file header
based on a value in the table, like this?

#+TBLNAME:testtwo
 | a.png | "G" | "E" | "F" | [[img/a.png]] |
#+TBLFM: $4='(sbe plotTest[:file img/$1] (A $2)(B $3)(C $4))

Thanks,

Myles

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

* Re: sbe with :file header arg?
  2011-10-07 17:49 sbe with :file header arg? Myles English
@ 2011-10-07 18:22 ` Eric Schulte
  2011-10-10 12:15   ` Myles English
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Schulte @ 2011-10-07 18:22 UTC (permalink / raw)
  To: emacs-orgmode

Myles English <mylesenglish@gmail.com> writes:

> Hello,
>
> I think I have one case of strange behaviour and one feature request, if it
> isn't already possible.
>
> I would like to make one plot per row of a table.  This is useful because the
> contents of the row may be parameters in an R session, and a link to the
> resulting plot can be put in the last cell of each row.
>

Hi Myles,

I've just updated the sbe macro so that it is now possible to pass
header arguments through to the called code block.  Specifically, if the
value immediately following the code block name in an sbe call is a
string rather than a variable specification list it will be added to the
code blocks header arguments.  See the example below.

  #+source: test-sbe
  #+begin_src emacs-lisp :var x=0 :var y=0
    (+ x y)
  #+end_src

  | 1 | 2 | :file eric.png | eric.png |
  #+TBLFM: @1$4='(sbe test-sbe $3 (x $1) (y $2))

  | 1 | 2 | :file eric.png | 3 |
  #+TBLFM: @1$4='(sbe test-sbe (x $1) (y $2))

Hope this helps -- Eric

>
> The following source block makes a plot:
>
> #+source: plotTest
> #+headers: :var A="A" :var B="B" :var C="C"
> #+begin_src R :file nofile.png :results graphics :session b
>   plot( 1,1, ylab=A, xlab=B)
> text(0.8,0.8,C)
> #+end_src
> #+results: plotTest
> [[file:nofile.png]]
>
> and the source block may be called using this table:
>
> #+TBLNAME: testtbl
>  | "5" | "X" | "Y" | nofile.png |
>  |   7 | P   | "Q" | nofile.png |
> #+TBLFM: $4='(sbe plotTest (A $1)(B $2)(C $3))
>
> executing that shows up the strange behaviour because the R interpreter
> contains:
>
>> > png(filename="nofile.png")
>> A <- "5"
>> B <- "X"
>> C <- "Y"
>>   plot( 1,1, ylab=A, xlab=B)
>> text(0.8,0.8,C)
>> dev.off()
> null device 
>           1 
>> > png(filename="nofile.png")
>> A <- 7
>> B <- "/home/myles/org/org/nofile.png"       <------  STRANGE, NO?
>> C <- "Q"
>>   plot( 1,1, ylab=A, xlab=B)
>> text(0.8,0.8,C)
>> dev.off()
> null device 
>           1
>
> Now the feature request; would it be possible to pass a :file header
> based on a value in the table, like this?
>
> #+TBLNAME:testtwo
>  | a.png | "G" | "E" | "F" | [[img/a.png]] |
> #+TBLFM: $4='(sbe plotTest[:file img/$1] (A $2)(B $3)(C $4))
>
> Thanks,
>
> Myles
>

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/

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

* Re: sbe with :file header arg?
  2011-10-07 18:22 ` Eric Schulte
@ 2011-10-10 12:15   ` Myles English
  0 siblings, 0 replies; 3+ messages in thread
From: Myles English @ 2011-10-10 12:15 UTC (permalink / raw)
  To: emacs-orgmode


Hi Eric,

>> On Fri, 07 Oct 2011 12:22:13 -0600, Eric Schulte said:

  > Myles English <mylesenglish@gmail.com> writes:
  >> I would like to make one plot per row of a table.  This is useful
  >> because the contents of the row may be parameters in an R session,
  >> and a link to the resulting plot can be put in the last cell of
  >> each row.
  >> 

  > I've just updated the sbe macro so that it is now possible to pass
  > header arguments through to the called code block.  Specifically, if
  > the value immediately following the code block name in an sbe call
  > is a string rather than a variable specification list it will be
  > added to the code blocks header arguments.  See the example below.

  >   #+source: test-sbe #+begin_src emacs-lisp :var x=0 :var y=0 (+ x
  > y) #+end_src

  >   | 1 | 2 | :file eric.png | eric.png | #+TBLFM: @1$4='(sbe test-sbe
  > $3 (x $1) (y $2))

  >   | 1 | 2 | :file eric.png | 3 | #+TBLFM: @1$4='(sbe test-sbe (x $1)
  > (y $2))

Thank you very much, it works well and replaces several manual steps.

Myles

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

end of thread, other threads:[~2011-10-10 12:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-07 17:49 sbe with :file header arg? Myles English
2011-10-07 18:22 ` Eric Schulte
2011-10-10 12:15   ` Myles English

Code repositories for project(s) associated with this 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).