emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* babel R: should/does order of parameters matter?
@ 2011-03-20 14:19 Myles English
  2011-03-23  3:03 ` Eric Schulte
  0 siblings, 1 reply; 4+ messages in thread
From: Myles English @ 2011-03-20 14:19 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

First of all thanks very much for all the very well explained help
given in previous threads I have started.

Now, I have found different results arise from a difference in position
of parameters (I'm using commit c01c2ad Fri Mar 18, R version 2.12.20,
Feb 25):


#+TBLNAME: data
| x | parameter | value |
|---+-----------+-------|
| 0 | heat      |    30 |
| 1 | heat      |    30 |

This next block works as I expect and returns the column names:

#+source: namesNFirst
#+begin_src R  :var N :var tbl :var param :colnames yes
       names(tbl)
#+end_src

#+call: namesNFirst(N=10,tbl=data,param="heat")

#+results: namesNFirst(N=10,tbl=data,param="heat")
| x         |
| parameter |
| value     |

Now, I would expect this to return the same result as above:

#+source: namesNLast
#+begin_src R  :var tbl :var param :var N :colnames yes 
       names(tbl)
#+end_src

#+call: namesNLast(tbl=data,param="heat",N=10)

but it doesn't:

#+results: namesNLast(tbl=data,param="heat",N=10)
| X0   |
| heat |
| X30  |

Removing the string parameter 'param', and again it works as expected:

#+source: namesNoParam
#+begin_src R  :var tbl :var N :colnames yes 
       names(tbl)
#+end_src

#+call: namesNoParam(tbl=data,N=10)

#+results: namesNoParam(tbl=data,N=10)
| x         |
| parameter |
| value     |

I can't find any difference R-side when using :session.  At this stage
I am asking for help; is this intended or a bug?.

Thanks.

Myles

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

* Re: babel R: should/does order of parameters matter?
  2011-03-20 14:19 babel R: should/does order of parameters matter? Myles English
@ 2011-03-23  3:03 ` Eric Schulte
  2011-03-29 15:57   ` Myles English
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Schulte @ 2011-03-23  3:03 UTC (permalink / raw)
  To: Myles English; +Cc: emacs-orgmode

Hi Myles,

I believe the problem here is that your :var header argument syntax is
wrong.  A :var header argument must have a name, and equals sign, and an
assignment for the variable, e.g.

#+begin_src sh :var name="eric"
  echo $name
#+end_src

#+results:
: eric

Please see the online manual for more information on the :var header
argument. http://orgmode.org/manual/var.html#var

Best -- Eric

Myles English <mylesenglish@gmail.com> writes:

> Hello,
>
> First of all thanks very much for all the very well explained help
> given in previous threads I have started.
>
> Now, I have found different results arise from a difference in position
> of parameters (I'm using commit c01c2ad Fri Mar 18, R version 2.12.20,
> Feb 25):
>
>
> #+TBLNAME: data
> | x | parameter | value |
> |---+-----------+-------|
> | 0 | heat      |    30 |
> | 1 | heat      |    30 |
>
> This next block works as I expect and returns the column names:
>
> #+source: namesNFirst
> #+begin_src R  :var N :var tbl :var param :colnames yes
>        names(tbl)
> #+end_src
>
> #+call: namesNFirst(N=10,tbl=data,param="heat")
>
> #+results: namesNFirst(N=10,tbl=data,param="heat")
> | x         |
> | parameter |
> | value     |
>
> Now, I would expect this to return the same result as above:
>
> #+source: namesNLast
> #+begin_src R  :var tbl :var param :var N :colnames yes 
>        names(tbl)
> #+end_src
>
> #+call: namesNLast(tbl=data,param="heat",N=10)
>
> but it doesn't:
>
> #+results: namesNLast(tbl=data,param="heat",N=10)
> | X0   |
> | heat |
> | X30  |
>
> Removing the string parameter 'param', and again it works as expected:
>
> #+source: namesNoParam
> #+begin_src R  :var tbl :var N :colnames yes 
>        names(tbl)
> #+end_src
>
> #+call: namesNoParam(tbl=data,N=10)
>
> #+results: namesNoParam(tbl=data,N=10)
> | x         |
> | parameter |
> | value     |
>
> I can't find any difference R-side when using :session.  At this stage
> I am asking for help; is this intended or a bug?.
>
> Thanks.
>
> Myles

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

* Re: babel R: should/does order of parameters matter?
  2011-03-23  3:03 ` Eric Schulte
@ 2011-03-29 15:57   ` Myles English
  2011-03-29 16:33     ` Eric Schulte
  0 siblings, 1 reply; 4+ messages in thread
From: Myles English @ 2011-03-29 15:57 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode

Eric,

On 23 March 2011 03:03, Eric Schulte <schulte.eric@gmail.com> wrote:
> I believe the problem here is that your :var header argument syntax is
> wrong.  A :var header argument must have a name, and equals sign, and an
> assignment for the variable, e.g.
>
> #+begin_src sh :var name="eric"
>  echo $name
> #+end_src
>
> #+results:
> : eric

Thanks for your reply, I think I deviated from the correct syntax
while experimenting.  After some more research I think I may have
found either a bug or an omission from the manual.

In order for R to assign column names to the resulting dataframe,
an argument that is a table name must be the first argument at
the point where a function is called from, whether it is executed
directly (from within a source block) or by a #+call.

The full org file that I believe verifies the above statement is
http://pastebin.com/iixQdS0G , but to illustrate the issue:

#+TBLNAME: data
| x | parameter | value |
|---+-----------+-------|
| 0 | heat      |    30 |
| 1 | heat      |    30 |

#+source: func5
#+begin_src R :var name=data :var a="one" :colnames yes
names(name)
#+end_src

executing directly works as expected:

#+results: func5
| x         |
|-----------|
| x         |
| parameter |
| value     |

try a basic call (ignores :colnames):

#+call: func5(name=data, a="two")

#+results: func5(name=data, a="two")
| x         |
| parameter |
| value     |

however, with the table argument last:

#+call: func5(a="two",name=data)

#+results: func5(a="two",name=data)
| X0   |
| heat |
| X30  |

of course I have also tried swapping the order of the arguments
in the source block (and the #+calls) and the statement still stands.

Is this confirmable as a bug or have I gone wrong again somewhere?

Thanks,

Myles

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

* Re: babel R: should/does order of parameters matter?
  2011-03-29 15:57   ` Myles English
@ 2011-03-29 16:33     ` Eric Schulte
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Schulte @ 2011-03-29 16:33 UTC (permalink / raw)
  To: Myles English; +Cc: emacs-orgmode

>
> #+TBLNAME: data
> | x | parameter | value |
> |---+-----------+-------|
> | 0 | heat      |    30 |
> | 1 | heat      |    30 |
>
> #+source: func5
> #+begin_src R :var name=data :var a="one" :colnames yes
> names(name)
> #+end_src
>
> executing directly works as expected:
>
> #+results: func5
> | x         |
> |-----------|
> | x         |
> | parameter |
> | value     |
>

Agreed.

>
> try a basic call (ignores :colnames):
>
> #+call: func5(name=data, a="two")
>
> #+results: func5(name=data, a="two")
> | x         |
> | parameter |
> | value     |
>

Yes, that is because the :colnames header argument applies to the
original code block, but not to the call line.  Pass the :colnames
header argument to call line as follows

#+call: func5(name=data, a="two") :colnames yes

#+results: func5(name=data, a="two")
| x         |
|-----------|
| x         |
| parameter |
| value     |

see http://orgmode.org/manual/Evaluating-code-blocks.html for
information on the call line syntax

>
> however, with the table argument last:
>
> #+call: func5(a="two",name=data)
>
> #+results: func5(a="two",name=data)
> | X0   |
> | heat |
> | X30  |
>
> of course I have also tried swapping the order of the arguments
> in the source block (and the #+calls) and the statement still stands.
>

Hmm, now this is weird, the order of the arguments should matter to the
call line, since they are named, they should map directly to the
appropriate variable in the original code block.  I'll have to look into
this, thanks for bringing it up.

>
> Is this confirmable as a bug or have I gone wrong again somewhere?
>

The order of arguments issue is a bug, however the :colnames behavior is
as expected (although the semantics of header arguments in call lines
are admittedly tricky).

Thanks -- Eric

>
> Thanks,
>
> Myles

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

end of thread, other threads:[~2011-03-29 16:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-20 14:19 babel R: should/does order of parameters matter? Myles English
2011-03-23  3:03 ` Eric Schulte
2011-03-29 15:57   ` Myles English
2011-03-29 16:33     ` Eric Schulte

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