In R packages there can be a directory exec
which contains some executable scripts. I have such a script called json_merge.R
in my package numericprojection
. This gets installed to ~/R/x86_64-redhat-linux-gnu-library/3.6/numericprojection/exec/json_merge.R
.
To execute it I can of course specify that particular path and call it with Rscript
from the command line. I was wondering whether there is some way to have R resolve this path such that I could just specify json_merge.R
and numericprojection
.
In the meantime I constructed this here:
r_libs_user="$(Rscript -e "cat(Sys.getenv('R_LIBS_USER'))")"
script="$r_libs_user/numericprojection/exec/projected_merge.R"
script="${script/#\~/$HOME}" # https://stackoverflow.com/a/27485157/653152
"$script"