emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Erik Iverson <eriki@ccbr.umn.edu>
To: Graham Smith <myotisone@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: [babel] multiple result outputs from function
Date: Tue, 16 Mar 2010 13:39:50 -0500	[thread overview]
Message-ID: <4B9FD076.3050709@ccbr.umn.edu> (raw)
In-Reply-To: <2c75873c1003161126r36c5e2c0kfa3f3540bf9ec7cf@mail.gmail.com>

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

  parent reply	other threads:[~2010-03-16 18:40 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-16 18:26 [babel] multiple result outputs from function Graham Smith
2010-03-16 18:35 ` Dan Davison
2010-03-16 18:43   ` Graham Smith
2010-03-16 18:39 ` Erik Iverson [this message]
2010-03-16 18:53   ` Graham Smith
2010-03-16 19:26     ` Dan Davison
2010-03-16 19:38       ` Graham Smith

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B9FD076.3050709@ccbr.umn.edu \
    --to=eriki@ccbr.umn.edu \
    --cc=emacs-orgmode@gnu.org \
    --cc=myotisone@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).