简体   繁体   English

如何在linux shell命令中运行自定义的R函数?

[英]how to run a self-defined R function in linux shell command?

I want to run a self-defined function in the R file with name "run.plot.R" on a remote HPC with linux. 我想在具有Linux的远程HPC上的名称为“ run.plot.R”的R文件中运行一个自定义函数。

I type the linux command : 我输入linux命令:

R CMD run.plot.R

But it seems the function code is not read by R from the file yet. 但是似乎R尚未从文件中读取功能代码。 How can I load the function file into R and then run it? 如何将功能文件加载到R中然后运行?

Three options are: 三个选项是:

Rscript run.plot.R

or 要么

R CMD BATCH run.plot.R

or use the littler app, see http://dirk.eddelbuettel.com/code/littler.html 或使用littler应用程序,请访问http://dirk.eddelbuettel.com/code/littler.html

All three of these run in a non-interactive mode. 所有这三个都以非交互模式运行。

If you want to run interactively, either 如果要交互式运行,则可以

R --file run.plot.R

or just start R via 或只是通过R开始

R

then once R is running 然后一旦R运行

source("run.plot.R")

However, all of the above assumes that run.plot.R contains function code and the R calls to run those R functions. 但是,以上所有假设都假设run.plot.R包含函数代码并且R调用运行那些R函数。

Finally, given the filename, whether any plots are or can b generated will depend on how is running on the remote Linux servers, whether X is forwarding over the connection you are using, etc. 最后,在给定文件名的情况下,是否生成任何图都可以取决于远程Linux服务器上的运行方式,X是否通过您正在使用的连接转发等等。

I often use 我经常用

R --vanilla -f <filename>

The --vanilla flag is used to ensure a consistent R environment among multiple users. --vanilla标志用于确保多个用户之间具有一致的R环境。 Depending on your needs, you may or may not want to use it. 根据您的需要,您可能会或可能不想使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM