What is the difference between running R with Rscript versus the interactive REPL?

Quick Overview

Asks how running R through Rscript differs from working in the interactive R console. Tests understanding of non-interactive sessions: what gets printed, how errors and exit codes behave, how scripts receive arguments, and why the same code can act differently in a batch job.

What is the difference between running R with Rscript versus the interactive REPL?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

What is the difference between running R with `Rscript` versus the interactive REPL? Explain when you would use each and how the same code can behave differently in the two modes. ```hint Start from one function Compare what `interactive()` returns in each mode, then follow the consequences for printed output, errors, input prompts and the saved workspace. ``` ### What a Strong Answer Covers - What each mode is for and how each one is started. - Behavioral differences that follow from a non-interactive session: error handling and exit status, input prompts, workspace restore and save, graphics devices. - Exactly when results are printed automatically and when `print()` or `cat()` is required. - How a script receives command-line arguments and reports success or failure to the program that called it. ### Follow-up Questions - Why might a ggplot that appears in RStudio produce no plot when the same code runs inside a loop or a sourced file? - How do you make an R script fail a cron job or CI step with a non-zero exit code? - How does `R CMD BATCH` differ from `Rscript`? - How would you keep a batch run reproducible when a user's `.Rprofile` sets options or loads packages?

Overview: Asks how running R through Rscript differs from working in the interactive R console. Tests understanding of non-interactive sessions: what gets printed, how errors and exit codes behave, how scripts receive arguments, and why the same code can act differently in a batch job.

General logo
General
Nov 24, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

What is the difference between running R with Rscript versus the interactive REPL? Explain when you would use each and how the same code can behave differently in the two modes.

What a Strong Answer Covers Guidance

  • What each mode is for and how each one is started.
  • Behavioral differences that follow from a non-interactive session: error handling and exit status, input prompts, workspace restore and save, graphics devices.
  • Exactly when results are printed automatically and when print() or cat() is required.
  • How a script receives command-line arguments and reports success or failure to the program that called it.

Follow-up Questions Guidance

  • Why might a ggplot that appears in RStudio produce no plot when the same code runs inside a loop or a sourced file?
  • How do you make an R script fail a cron job or CI step with a non-zero exit code?
  • How does R CMD BATCH differ from Rscript ?
  • How would you keep a batch run reproducible when a user's .Rprofile sets options or loads packages?