emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Babel-R TBLFM example
@ 2014-06-25  6:55 Shiyuan
  2014-07-28 13:21 ` Bastien
  0 siblings, 1 reply; 9+ messages in thread
From: Shiyuan @ 2014-06-25  6:55 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1544 bytes --]

Hi all,
    I am looking at the Babel R example in
http://orgmode.org/worg/org-tutorials/org-R/org-R.html

This short example show how to use code block in Org Tables.
The example first makes an org-mode table, which I can follow and reproduce
the result:

#+name: tbl-example-data()
#+begin_src R
runif(n=5, min=0, max=1)
#+end_src

#+RESULTS: tbl-example-data
|  0.118510485393927 |
|  0.742342338664457 |
|  0.438421099446714 |
| 0.0867570964619517 |
|  0.604204315226525 |

Then it defines r source code block and use TBLFM

#+name: R-mean(x)
#+begin_src R
mean(x)
#+end_src

#+RESULTS: R-mean

#+tblname: summaries
| mean   |
|--------|
| #ERROR |
#+TBLFM: @2$1='(sbe "R-mean" (x "tbl-example-data()"))

When I export to html(C-c C-e h o), the  #+TBLFM seems to be ignored and
shows  no effect. When I place my cursor in the table and recalculate the
table formula using C-u C-c C-c in the table. I got an error as shown
above.   In the *Message* buffer, I can see the following messages.
byte-code: Beginning of buffer [8 times]
Re-applying formulas to full table...
Re-applying formula to field: @2$1
Re-applying formulas to full table...(line 1)
Re-applying formula to field: @2$1
Re-applying formulas to 1 lines...done
Re-applying formulas...done [2 times]

Any steps I missed? I am using org mode 8.2.6

Also, I found this tutorial for org-R
http://orgmode.org/worg/org-tutorials/org-R/org-R.html, however, the
org-R-apply function seems no longer available in my org mode 8.2.6. Is
org-R supposed to be deprecated?

Thanks.

Shiyuan

[-- Attachment #2: Type: text/html, Size: 2379 bytes --]

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

* Re: Babel-R TBLFM example
  2014-06-25  6:55 Babel-R TBLFM example Shiyuan
@ 2014-07-28 13:21 ` Bastien
  2014-07-29  6:15   ` Shiyuan
  0 siblings, 1 reply; 9+ messages in thread
From: Bastien @ 2014-07-28 13:21 UTC (permalink / raw)
  To: Shiyuan; +Cc: emacs-orgmode

Hi Shiyuan,

Shiyuan <gshy2014@gmail.com> writes:

> Also, I found this tutorial for org-R http://orgmode.org/worg/
> org-tutorials/org-R/org-R.html, however, the org-R-apply function
> seems no longer available in my org mode 8.2.6. Is org-R supposed to
> be deprecated?

No, but it's moving.  Since ob-R.el is perhaps one of the most useful
Babel library out there, we need to document the changes carefully in
etc/ORG-NEWS.

-- 
 Bastien

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

* Re: Babel-R TBLFM example
  2014-07-28 13:21 ` Bastien
@ 2014-07-29  6:15   ` Shiyuan
  2014-07-29 13:20     ` Bastien
  0 siblings, 1 reply; 9+ messages in thread
From: Shiyuan @ 2014-07-29  6:15 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode@gnu.org

[-- Attachment #1: Type: text/plain, Size: 745 bytes --]

Thanks Bastien. I see ob-R.el from org-mode repos has been updated. So is
the org-R from git-repos ready to use? Could you suggest  a good place to
start learning the new org-R? The source file ob-R.el?

Shiyuan


On Mon, Jul 28, 2014 at 6:21 AM, Bastien <bzg@gnu.org> wrote:

> Hi Shiyuan,
>
> Shiyuan <gshy2014@gmail.com> writes:
>
> > Also, I found this tutorial for org-R http://orgmode.org/worg/
> > org-tutorials/org-R/org-R.html, however, the org-R-apply function
> > seems no longer available in my org mode 8.2.6. Is org-R supposed to
> > be deprecated?
>
> No, but it's moving.  Since ob-R.el is perhaps one of the most useful
> Babel library out there, we need to document the changes carefully in
> etc/ORG-NEWS.
>
> --
>  Bastien
>

[-- Attachment #2: Type: text/html, Size: 1311 bytes --]

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

* Re: Babel-R TBLFM example
  2014-07-29  6:15   ` Shiyuan
@ 2014-07-29 13:20     ` Bastien
  2014-08-24 23:02       ` Shiyuan
  0 siblings, 1 reply; 9+ messages in thread
From: Bastien @ 2014-07-29 13:20 UTC (permalink / raw)
  To: Shiyuan; +Cc: emacs-orgmode@gnu.org

Hi Shiyuan,

Shiyuan <gshy2014@gmail.com> writes:

> Thanks Bastien. I see ob-R.el from org-mode repos has been updated.
> So is the org-R from git-repos ready to use? Could you suggest  a
> good place to start learning the new org-R? The source file ob-R.el?

The recent committers to ob-R.el we be more in a position to help here
but yes, reading the source is certainly a good start.

I hope we will have a clear picture of what changed in ob-R.el in 8.3,
together with updated tutorials.

Best,

-- 
 Bastien

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

* Re: Babel-R TBLFM example
  2014-07-29 13:20     ` Bastien
@ 2014-08-24 23:02       ` Shiyuan
  2014-08-25  7:51         ` Sebastien Vauban
  0 siblings, 1 reply; 9+ messages in thread
From: Shiyuan @ 2014-08-24 23:02 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode@gnu.org

[-- Attachment #1: Type: text/plain, Size: 2188 bytes --]

I am looking at a simpler example, the pie-chart example as in this link:
http://orgmode.org/worg/org-contrib/babel/intro.html#literate-programming

This example(src code attached in the end) first generates a table by a
shell command and then run a R one-liner which uses the table.  However,
when the R code is evaluated, I got an error about the object dirs not
found.  This is what I got in the buffer running R:
-------------------------------
options(STERM='iESS', str.dendrogram.last="'", editor='emacsclient',
show.error.locations=TRUE)
>
Error in pie(dirs[, 1], labels = dirs[, 2]) (from
test-org-babe-meta-programming.org@24170fIx#1) : object 'dirs' not found
-----------------------------------------------

It looks like that the conversion is wrong.  When I run
`org-babel-expand-src-block`
on the R source code, I don't see the R object dirs is expanded to
anything. I don't understand how the conversion works, and how Babel passes
the table to R. Any explanation is appreciated. Which function/file should
I look at? Are there working examples for passing a table to R? Thanks.

Shiyuan


------------------------------
#+name: directories
#+begin_src shell :results replace
  cd ~ && du -sc * |grep -v total
#+end_src

#+RESULTS: directories
|       8 | #*message*-20140319-231047# |
| 1168376 | Documents                   |
| 9952288 | Downloads                   |
|       8 | xmodmap2~                   |

#+name: directory-pie-chart(dirs = directories)
#+begin_src R :session R-pie-example :file ~/tmp/dirs.png
  pie(dirs[,1], labels = dirs[,2])
#+end_src


On Tue, Jul 29, 2014 at 6:20 AM, Bastien <bzg@gnu.org> wrote:

> Hi Shiyuan,
>
> Shiyuan <gshy2014@gmail.com> writes:
>
> > Thanks Bastien. I see ob-R.el from org-mode repos has been updated.
> > So is the org-R from git-repos ready to use? Could you suggest  a
> > good place to start learning the new org-R? The source file ob-R.el?
>
> The recent committers to ob-R.el we be more in a position to help here
> but yes, reading the source is certainly a good start.
>
> I hope we will have a clear picture of what changed in ob-R.el in 8.3,
> together with updated tutorials.
>
> Best,
>
> --
>  Bastien
>

[-- Attachment #2: Type: text/html, Size: 3478 bytes --]

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

* Re: Babel-R TBLFM example
  2014-08-24 23:02       ` Shiyuan
@ 2014-08-25  7:51         ` Sebastien Vauban
  2014-08-26  6:18           ` Shiyuan
  0 siblings, 1 reply; 9+ messages in thread
From: Sebastien Vauban @ 2014-08-25  7:51 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Shiyuan wrote:
> I am looking at a simpler example, the pie-chart example as in this link:
> http://orgmode.org/worg/org-contrib/babel/intro.html#literate-programming
>
> This example(src code attached in the end) first generates a table by a
> shell command and then run a R one-liner which uses the table.  However,
> when the R code is evaluated, I got an error about the object dirs not
> found.  This is what I got in the buffer running R:
> -------------------------------
> options(STERM='iESS', str.dendrogram.last="'", editor='emacsclient',
> show.error.locations=TRUE)
>>
> Error in pie(dirs[, 1], labels = dirs[, 2]) (from
> test-org-babe-meta-programming.org@24170fIx#1) : object 'dirs' not found
> -----------------------------------------------
>
> It looks like that the conversion is wrong.  When I run
> `org-babel-expand-src-block`
> on the R source code, I don't see the R object dirs is expanded to
> anything. I don't understand how the conversion works, and how Babel passes
> the table to R. Any explanation is appreciated. Which function/file should
> I look at? Are there working examples for passing a table to R? Thanks.
>
> #+name: directories
> #+begin_src shell :results replace
>   cd ~ && du -sc * |grep -v total
> #+end_src
>
> #+RESULTS: directories
> |       8 | #*message*-20140319-231047# |
> | 1168376 | Documents                   |
> | 9952288 | Downloads                   |
> |       8 | xmodmap2~                   |
>
> #+name: directory-pie-chart(dirs = directories)
> #+begin_src R :session R-pie-example :file ~/tmp/dirs.png
>   pie(dirs[,1], labels = dirs[,2])
> #+end_src

AFAICT, the arguments to code blocks may not be defined and set in the
`name' line anymore: this must be done on the `begin_src' line.

So, the following should work:

  #+name: directory-pie-chart
  #+begin_src R :var dirs=directories :session R-pie-example :file ~/tmp/dirs.png
    pie(dirs[,1], labels = dirs[,2])
  #+end_src

Best regards,
  Seb

-- 
Sebastien Vauban

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

* Re: Babel-R TBLFM example
  2014-08-25  7:51         ` Sebastien Vauban
@ 2014-08-26  6:18           ` Shiyuan
  2014-08-26  6:57             ` Thomas S. Dye
  0 siblings, 1 reply; 9+ messages in thread
From: Shiyuan @ 2014-08-26  6:18 UTC (permalink / raw)
  Cc: emacs-orgmode@gnu.org

[-- Attachment #1: Type: text/plain, Size: 2240 bytes --]

Yes, it works. Thanks, Sebastien.

Shiyuan


On Mon, Aug 25, 2014 at 12:51 AM, Sebastien Vauban <sva-news@mygooglest.com>
wrote:

> Shiyuan wrote:
> > I am looking at a simpler example, the pie-chart example as in this link:
> >
> http://orgmode.org/worg/org-contrib/babel/intro.html#literate-programming
> >
> > This example(src code attached in the end) first generates a table by a
> > shell command and then run a R one-liner which uses the table.  However,
> > when the R code is evaluated, I got an error about the object dirs not
> > found.  This is what I got in the buffer running R:
> > -------------------------------
> > options(STERM='iESS', str.dendrogram.last="'", editor='emacsclient',
> > show.error.locations=TRUE)
> >>
> > Error in pie(dirs[, 1], labels = dirs[, 2]) (from
> > test-org-babe-meta-programming.org@24170fIx#1) : object 'dirs' not found
> > -----------------------------------------------
> >
> > It looks like that the conversion is wrong.  When I run
> > `org-babel-expand-src-block`
> > on the R source code, I don't see the R object dirs is expanded to
> > anything. I don't understand how the conversion works, and how Babel
> passes
> > the table to R. Any explanation is appreciated. Which function/file
> should
> > I look at? Are there working examples for passing a table to R? Thanks.
> >
> > #+name: directories
> > #+begin_src shell :results replace
> >   cd ~ && du -sc * |grep -v total
> > #+end_src
> >
> > #+RESULTS: directories
> > |       8 | #*message*-20140319-231047# |
> > | 1168376 | Documents                   |
> > | 9952288 | Downloads                   |
> > |       8 | xmodmap2~                   |
> >
> > #+name: directory-pie-chart(dirs = directories)
> > #+begin_src R :session R-pie-example :file ~/tmp/dirs.png
> >   pie(dirs[,1], labels = dirs[,2])
> > #+end_src
>
> AFAICT, the arguments to code blocks may not be defined and set in the
> `name' line anymore: this must be done on the `begin_src' line.
>
> So, the following should work:
>
>   #+name: directory-pie-chart
>   #+begin_src R :var dirs=directories :session R-pie-example :file
> ~/tmp/dirs.png
>     pie(dirs[,1], labels = dirs[,2])
>   #+end_src
>
> Best regards,
>   Seb
>
> --
> Sebastien Vauban
>
>
>

[-- Attachment #2: Type: text/html, Size: 3184 bytes --]

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

* Re: Babel-R TBLFM example
  2014-08-26  6:18           ` Shiyuan
@ 2014-08-26  6:57             ` Thomas S. Dye
  2014-08-26  7:23               ` Sebastien Vauban
  0 siblings, 1 reply; 9+ messages in thread
From: Thomas S. Dye @ 2014-08-26  6:57 UTC (permalink / raw)
  To: Shiyuan; +Cc: emacs-orgmode@gnu.org

Aloha all,

>> AFAICT, the arguments to code blocks may not be defined and set in the
>> `name' line anymore: this must be done on the `begin_src' line.

or, on a separate #+header: line.

All the best,
Tom

-- 
Thomas S. Dye
http://www.tsdye.com

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

* Re: Babel-R TBLFM example
  2014-08-26  6:57             ` Thomas S. Dye
@ 2014-08-26  7:23               ` Sebastien Vauban
  0 siblings, 0 replies; 9+ messages in thread
From: Sebastien Vauban @ 2014-08-26  7:23 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Thomas S. Dye wrote:
> Aloha all,
>
>>> AFAICT, the arguments to code blocks may not be defined and set in the
>>> `name' line anymore: this must be done on the `begin_src' line.
>
> or, on a separate #+header: line.

Indeed.  I tend to forget to use that; thanks for mentioning it!

Best regards,
  Seb

-- 
Sebastien Vauban

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

end of thread, other threads:[~2014-08-26  7:23 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-25  6:55 Babel-R TBLFM example Shiyuan
2014-07-28 13:21 ` Bastien
2014-07-29  6:15   ` Shiyuan
2014-07-29 13:20     ` Bastien
2014-08-24 23:02       ` Shiyuan
2014-08-25  7:51         ` Sebastien Vauban
2014-08-26  6:18           ` Shiyuan
2014-08-26  6:57             ` Thomas S. Dye
2014-08-26  7:23               ` Sebastien Vauban

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