2
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ About the first part of your question: why do not environment variables and Sys.getenv() work? $\endgroup$
    – Ott Toomet
    Oct 21, 2017 at 21:12

1 Answer 1

1
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ Yeah there is a library in R that does exactly that, I found about it yesterday, but I'll try it $\endgroup$
    – Ka_Papa
    Aug 21, 2017 at 19:18
  • $\begingroup$ Or save it to a temporary file. Depends on what you want to do with it. $\endgroup$
    – Spacedman
    Aug 22, 2017 at 17:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.