在R程序包there can be a directory exec
中,其中包含一些可执行脚本。我的程序包exec
中有一个名为json_merge.R
的脚本。这将安装到numericprojection
。
要执行它,我当然可以指定该特定路径,并在命令行中使用~/R/x86_64-redhat-linux-gnu-library/3.6/numericprojection/exec/json_merge.R
对其进行调用。我想知道是否有某种方法可以让R解析此路径,以便我可以仅指定Rscript
和json_merge.R
。
同时,我在这里构造了这个:
numericprojection
这就是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"
命令的作用。在您的情况下,该命令应如下所示:
system.file
并将返回:
system.file("exec", "json_merge.R", package = "numericprojection")
如果是文件的安装位置。
但是,我认为您的问题很可能是基于评论中概述的误解。