From mboxrd@z Thu Jan 1 00:00:00 1970 From: Erik Iverson Subject: Re: [babel] multiple result outputs from function Date: Tue, 16 Mar 2010 13:39:50 -0500 Message-ID: <4B9FD076.3050709@ccbr.umn.edu> References: <2c75873c1003161126r36c5e2c0kfa3f3540bf9ec7cf@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NrbgT-0002YX-UN for emacs-orgmode@gnu.org; Tue, 16 Mar 2010 14:40:05 -0400 Received: from [140.186.70.92] (port=39936 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NrbgP-0002VR-K6 for emacs-orgmode@gnu.org; Tue, 16 Mar 2010 14:40:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NrbgK-0006jO-OD for emacs-orgmode@gnu.org; Tue, 16 Mar 2010 14:39:58 -0400 Received: from walleye.ccbr.umn.edu ([128.101.116.11]:2431) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NrbgK-0006jC-IC for emacs-orgmode@gnu.org; Tue, 16 Mar 2010 14:39:56 -0400 In-Reply-To: <2c75873c1003161126r36c5e2c0kfa3f3540bf9ec7cf@mail.gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Graham Smith Cc: emacs-orgmode@gnu.org Graham - Graham Smith wrote: > Below is a function that I am trying to run in orgmode/babel. > > It seems to run OK, but instead of printing out three values, its only > printing the final result. > > Once again, i would appreciate some help with what I am missing. > > Thanks, > > Graham > > > #+srcname: CI_function > #+begin_src R :session daf > summary.ci<-function(x){ > xbar<-mean(x) > sigma<-sd(x) > n<-length(x) > sem<-sigma/sqrt(n) > lower.ci<-xbar+sem*qnorm(0.025) > upper.ci<-xbar+sem*qnorm(0.975) > print (xbar) > print (lower.ci) > print (upper.ci) > } > #+end_src > > #+srcname: SumFlowering2005 > #+begin_src R :session daf > summary.ci(daf$Flower[daf$YEAR=="2005"]) > #+end_src > > #+results: SumFlowering2005 > : 1.97860201016947 > From org-babel docs... The following options are mutually exclusive, and specify how the results should be collected from the source code block. ------------------------------------------------------ value This is the default. The result is the value of the last statement in the source code block. This header argument places Org-babel in functional mode. Note that in some languages, e.g., python, use of this result type requires that a return statement be included in the body of the source code block. E.g., :results value. output The result is the collection of everything printed to stdout during the execution of the source code block. This header argument places Org-babel in scripting mode. E.g., :results output. ------------------------------------------------------- So, add ":results output" to your source header block. Or, you might want to define your R function to return a list of the three components you're after for further processing, and then not have to include ":results output" Instead of the 3 print statements, which don't create objects, you could substitute list(xbar, lower.ci, upper.ci) --Erik