From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sebastien Vauban Subject: Re: Babel-R TBLFM example Date: Mon, 25 Aug 2014 09:51:10 +0200 Message-ID: <861ts5knwx.fsf@somewhere.org> References: <8738dl1jm7.fsf@bzg.ath.cx> <8761igfgio.fsf@bzg.ath.cx> Mime-Version: 1.0 Content-Type: text/plain Return-path: 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-mXXj517/zsQ@public.gmane.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org-mXXj517/zsQ@public.gmane.org To: emacs-orgmode-mXXj517/zsQ@public.gmane.org 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