Passing variables and values from an R script to a shell script


I'm working with a shell script(#!/bin/sh) and I wanted to know if there is a way to call variables with their values from an Rscript that I have called in my Shell script. If that doesn't make sense I want to create, for example a data frame data=data.frame(a=seq(1,5), b=seq(1,5)) in a script called test.r and then call that variable, with it's content in my shell script, i.e to print it with an echo:

echo $data


Posted 2017-08-19T10:48:46.027

Reputation: 129

About the first part of your question: why do not environment variables and Sys.getenv() work? – Ott Toomet – 2017-10-21T21:12:32.760



The Bash feature you want is called command substitution, e.g:

echo $(./test.r)

That will echo the output of your Rscript. Alternatively you could capture it in an environment variable.


Posted 2017-08-19T10:48:46.027

Reputation: 328

Yeah there is a library in R that does exactly that, I found about it yesterday, but I'll try it – K_Patsak – 2017-08-21T19:18:23.267

Or save it to a temporary file. Depends on what you want to do with it. – Spacedman – 2017-08-22T17:24:05.743