Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use R's `browser()` function from command line when using `Rscript`

Tags:

r

pdb

How do I run a script with browser() in it from the command line in such a way that it halt's execution?

Rscript file.R 

Does not work for me. It seems I can only use browser() from R's interpreter. What am I doing wrong?

like image 944
quine Avatar asked Aug 17 '13 19:08

quine


People also ask

How do I run an R from the command line in Windows?

Starting R If R has been installed properly, simply entering R on the command line of a terminal should start the program. In Windows, the program is typically specified as the action performed when clicking on an icon. You can also use this method on a *NIX system that has a window manager such as KDE.

How do I run an Rscript in bash?

Use Rscript to run R from bash You can run it using Rscript test. r . And even better, if you add an initial shebang line #!/usr/bin/env Rscript in the script above and make it executable with chmod +x test. r , you can directly launch your R script with ./test.


1 Answers

R functions such as browser(), debugger(), or recover() only work interactively.

If your script does not take command-line arguments a simple workaround is to start R and source("myscript.R").

like image 104
lgautier Avatar answered Oct 04 '22 21:10

lgautier