I need to share config variables between various R and bash programmes. They all share various resources, especially a GRASS database.
I started by creating a bash script that sets up shell variables and then runs the R programme. This way R is blind to the shell variables:
$ cat testVars.R
Sys.getenv(c("WDIR","GDIR"))
$ cat testVars.sh
#!/bin/sh
WDIR="/Work/Project/"
GDIR=$WDIR"GRASSDATA"
Rscript testVars.R
$ ./testVars.sh
WDIR GDIR
"" ""
I then tried using the readRenviron
function in R, thinking it could be used to source a bash file setting up variables. However, this results in a different problem, R is unable to replace and concatenate variables like bash does:
$ cat testVars.R
readRenviron("./testVars.sh")
Sys.getenv(c("WDIR","GDIR"))
$ cat testVars.sh
#!/bin/sh
WDIR="/Work/Project/"
GDIR=$WDIR"GRASSDATA"
$ Rscript testVars.R
WDIR GDIR
"/Work/Project/" "$WDIRGRASSDATA"
YAML is supported to some extent in both languages, but it suffers from the same lack of replacement and concatenation facilities. For instance, with YAML I would need to repeat the working directory countless times in the configuration file.
So here is what I am looking for: a configuration format than can be used by both R and bash and also allows variable concatenation.