User Tools

Site Tools



This shows you the differences between two versions of the page.

Link to this comparison view

wiki:cluster_r_eof [2017/12/05 22:53]
wiki:cluster_r_eof [2020/07/17 06:39] (current)
Line 1: Line 1:
 +====== EOF method ​ ======
 +If we have a short R script or a single R function we can emberd this R command into a bash script and process it using one cores using the bash [[http://​​wiki/​End-of-file|EOF]] function.\\
 +The  //export// bash fonticon and the //​Sys.getenv()//​ R function allows to exchange variables between R and bash. We can use this functionality to embed an R command in bash.  ​
 +<code bash>
 +cd ~/​Documents/​multi_core
 +export mod
 +export t
 +export path
 +R --vanilla --no-readline ​  ​-q ​ << EOF
 +mod.t = Sys.getenv(c('​mod','​t','​path'​))
 +mod = as.numeric(mod.t[1])
 +t = as.numeric(mod.t[2])
 +path = as.character(mod.t[3])
 +my_output=paste("​We have processed ​ mod ",​mod,"​ and t ",​t,"​ ---- output path is   ",​path,​sep="​ ")
 +We can [[cluster_r_xargs|built an R]] script using Sys.getenv() and launch it in a loop using multi cpu