nietzschemouse
nietzschemouse

Reputation: 87

Is it possible to integrate R code into a shell script without calling an R script?

I have a shell script that calls an R script and they work just fine. However, I'm trying to make this more portable and reduce the number of files needed. Is it possible to push the code from my R script into the shell script?

It looks like

    #!/usr/bin/bash
    #Assorted shell code
    Rscript R_script.r arg1 arg2
    #Additional shell code

I want to see something like

    #!/usr/bin/bash
    #Assorted shell code
    R
    #Assorted R code
    q() #To return to shell

So far, I haven't found anything online that suggests this can be done, but I thought I'd ask.

Upvotes: 1

Views: 220

Answers (1)

Johannes Ranke
Johannes Ranke

Reputation: 469

If you are on Linux (which I assume as you are using bash) you can feed your R code to littler like this

#!/usr/bin/bash
echo "Hello"
echo 'x <- 2
print(x)' | r
echo "Done"

Upvotes: 2

Related Questions