emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Orgmode] [babel] multiple result outputs from function


From: Erik Iverson
Subject: Re: [Orgmode] [babel] multiple result outputs from function
Date: Tue, 16 Mar 2010 13:39:50 -0500
User-agent: Thunderbird 2.0.0.23 (X11/20090812)

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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]