From mboxrd@z Thu Jan 1 00:00:00 1970 From: Shiyuan Subject: Re: Babel-R TBLFM example Date: Mon, 25 Aug 2014 23:18:25 -0700 Message-ID: References: <8738dl1jm7.fsf@bzg.ath.cx> <8761igfgio.fsf@bzg.ath.cx> <861ts5knwx.fsf@somewhere.org> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=f46d0434bea664044905018245ad Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:50630) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XMA5M-0003AX-DN for emacs-orgmode@gnu.org; Tue, 26 Aug 2014 02:18:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XMA5K-0005t3-Ob for emacs-orgmode@gnu.org; Tue, 26 Aug 2014 02:18:28 -0400 Received: from mail-wg0-x22d.google.com ([2a00:1450:400c:c00::22d]:59672) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XMA5K-0005sr-Ef for emacs-orgmode@gnu.org; Tue, 26 Aug 2014 02:18:26 -0400 Received: by mail-wg0-f45.google.com with SMTP id x12so13834437wgg.28 for ; Mon, 25 Aug 2014 23:18:25 -0700 (PDT) In-Reply-To: <861ts5knwx.fsf@somewhere.org> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Cc: "emacs-orgmode@gnu.org" --f46d0434bea664044905018245ad Content-Type: text/plain; charset=UTF-8 Yes, it works. Thanks, Sebastien. Shiyuan On Mon, Aug 25, 2014 at 12:51 AM, Sebastien Vauban 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 > > > --f46d0434bea664044905018245ad Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Yes, it works. Thanks, Sebastien.=C2=A0

Shiyuan=C2=A0


On Mon, Aug 25, 2014 at 12:51 AM, Sebastien Vauban <s= va-news@mygooglest.com> wrote:
Shiyuan wrote:
> I am looking at a simpler example, the pie-chart example as in this li= nk:
> 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.=C2=A0 H= owever,
> when the R code is evaluated, I got an error about the object dirs not=
> found.=C2=A0 This is what I got in the buffer running R:
> -------------------------------
> options(STERM=3D'iESS', str.dendrogram.last=3D"'"= ;, editor=3D'emacsclient',
> show.error.locations=3DTRUE)
>>
> Error in pie(dirs[, 1], labels =3D dirs[, 2]) (from
> test-org-babe-meta-programming.org@24170fIx#1) : object 'dirs'= not found
> -----------------------------------------------
>
> It looks like that the conversion is wrong.=C2=A0 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 Bab= el passes
> the table to R. Any explanation is appreciated. Which function/file sh= ould
> I look at? Are there working examples for passing a table to R? Thanks= .
>
> #+name: directories
> #+begin_src shell :results replace
>=C2=A0 =C2=A0cd ~ && du -sc * |grep -v total
> #+end_src
>
> #+RESULTS: directories
> |=C2=A0 =C2=A0 =C2=A0 =C2=A08 | #*message*-20140319-231047# |
> | 1168376 | Documents=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0|
> | 9952288 | Downloads=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0|
> |=C2=A0 =C2=A0 =C2=A0 =C2=A08 | xmodmap2~=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|
>
> #+name: directory-pie-chart(dirs =3D directories)
> #+begin_src R :session R-pie-example :file ~/tmp/dirs.png
>=C2=A0 =C2=A0pie(dirs[,1], labels =3D dirs[,2])
> #+end_src

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

So, the following should work:

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

Best regards,
=C2=A0 Seb

--
Sebastien Vauban



--f46d0434bea664044905018245ad--