Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 205449

How to send R variable to bash and again being read by another R process?

$
0
0

I am trying to create a process mainly using R, where a R variable will be sent to bash and then another Rscript file will read that value from bash, do some calculation based on that.

My primary R code looks like below -

library(parallel) 
mclapply(letters, 
                    function(Let) 
                        return(system("/usr/lib/R/bin/Rscript '/opt/R/Try.R' $Let")), mc.cores = 6)

So, basically in above code, the individual letters are being sent to bash through variable Let, and then the 2nd R process 'Try.R' will read that value and print it.

My 'Try.R' looks like below -

GetValue = commandArgs(TRUE)

print(GetValue); flush.console()

quit(save = "no")

With above implementation, it doesnt look like the value of 'Let' variable is getting passed to bash. Can someone please help me with right approach. The codes above I put just for explanation purpose to describe what I am trying to do, and hence can be executed directly in R without passing to bash, however my actual process is quite complex so needs this kind of implementation.

Any pointer will be highly appreciated.

I am using Ubuntu 18 machine with latest R.


Viewing all articles
Browse latest Browse all 205449

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>