Is there a way to debug an RScript call in RStudio?

Imagine running an R script from the command line, like this:

Rscript prog.R xyz 

and I want to examine the code on a specific line.

Currently, I cannot just debug this interactively in RStudio, because I do not know how to pass arguments.

Since it is designed to be run from the command line, how can I debug the script through the command line / outside of RStudio?

+7
source share
1 answer

This is what I do - this is not formal debugging, but it works for me.

top of the prog.R script example:

 # uncomment this section to run using Rscript from command line: userprefs <- commandArgs(trailingOnly = TRUE) x <- userprefs[1] y <- userprefs[2] z <- userprefs[3] # uncomment this section to run within RStudio cat("you forgot to comment out the troubleshooting part!") x <- 1 y <- 2 z <- 3 

When troubleshooting in your script, comment out one or the other section depending on whether you are a source in RStudio or using RScript from the command line.

-1
source

Source: https://habr.com/ru/post/1260797/


All Articles