Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to provide expression to R from command-line but stop R from immediately exiting?

Tags:

r

I know how to start R from the command-line and execute an expression (e.g., R -e 'print("hello")') or take input from a file (e.g., R -f filename.r). However, in both cases, R runs the expression or commands in the file and then exits.

  • How can I change the above so that R doesn't exit after running the commands in the file or running the expression?
like image 985
Jeromy Anglim Avatar asked Oct 08 '11 06:10

Jeromy Anglim


People also ask

How do I stop R from command line?

To quit R you can either use the RStudio > Quit pull-down menu command or execute ⌘ + Q (OS X) or ctrl + Q (PC).

How do I run an R script from the command line with arguments?

Use the commandArgs() Function to Retrieve Arguments in R Arguments passed on the command line should be retrieved using the commandArgs() function. We will use it with the argument trailingOnly=TRUE . The function returns a character vector.

How do you go to the next line in R without running the code?

Use'SHIFT-ENTER' to get to a new line in R without executing the command.

How do I end code in R?

In the terminal, the “normal” way is Control + C – the “cancel” key combination. In the graphical R application and in RStudio, it's Escape .


1 Answers

Put your script in a file called .Rprofile in the current directory. Then start R normally.

like image 86
Tommy Avatar answered Oct 05 '22 05:10

Tommy