CyberPlayerOne
CyberPlayerOne

Reputation: 3180

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.

I type the linux command :

R CMD run.plot.R

But it seems the function code is not read by R from the file yet. How can I load the function file into R and then run it?

Upvotes: 1

Views: 960

Answers (2)

Gavin Simpson
Gavin Simpson

Reputation: 174778

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

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

then once R is running

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.

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.

Upvotes: 1

ALiX
ALiX

Reputation: 1031

I often use

R --vanilla -f <filename>

The --vanilla flag is used to ensure a consistent R environment among multiple users. Depending on your needs, you may or may not want to use it.

Upvotes: 0

Related Questions