Skip to content
Prev 177947 / 398502 Next

Returning Variables in R to Linux Shell

On Wed, Apr 22, 2009 at 3:48 PM, Bierbryer, Andrew
<abierbryer at klsdiversified.com> wrote:

            
You can use back-ticks (`) in most shells to capture output. So print
the value you want using R's cat() function, and capture it thus:

$ cat test.R
string <- 'TEST'
cat(string)

$ v=`R --slave --no-save < test.R `
$ echo $v
TEST

bash shell also allows $( ) notation:

$ v=$(R --slave --no-save < test.R )

 note the use of --slave to make R shut up about itself.

Barry