Hey everyone,

    I know that I can call 'R' from other scripts, and that I can make
command calls from 'R' (e.g., using system() ).  But how can I get 'R' to
RETURN values to the script that called it.  E.g., I would like to be able
to do something like the following (as a simpler example) from a bash
script:

#!/bin/bash

myTest=echo /usr/local/bin/R --no-restore --no-save -f testing.R.r

echo "myTest contains"
echo $myTest


    And ideally this should write out the results of the
"testing.R.rscript".  So that if the testing.
R.r script said something simple like:

myResult <- paste("Hello World")

    Then in the output of the bash script, it should say "myTest
contains\nHello World" or something quite similar.  But instead it says
myTest contains
R version 2.11.1 (2010-05-31) Copyright (C) 2010 The R Foundation for
Statistical Computing ISBN 3-900051-07-0 R is free software and comes with
ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain
conditions. Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale R is a
collaborative project with many contributors. Type 'contributors()' for more
information and 'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()'
for an HTML browser interface to help. Type 'q()' to quit R. > > > myResult
<- paste("Hello World") [1]

    As you can see, the return from the bash call is really just capturing
everything in the ST OUT once 'R' is called, which is not what I want.  I
have tried several variations, using a function - return combination, etc.
I have also looked through help pages & documentation.  As far as I can
tell, it seems no one ever bothers to get information OUT of 'R' and into
other scripts.  I could write to a csv file & read that file, but that seems
a REALLY clunky way to handle variable passing.

                                Thanks for any help!
                                          Regards,
                                                    Mike




"Telescopes and bathyscaphes and sonar probes of Scottish lakes,
Tacoma Narrows bridge collapse explained with abstract phase-space maps,
Some x-ray slides, a music score, Minard's Napoleanic war:
The most exciting frontier is charting what's already here."
  -- xkcd

--
Help protect Wikipedia. Donate now:
http://wikimediafoundation.org/wiki/Support_Wikipedia/en

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to