R different between batch and interactive modes

I would like to have a condition in my code that allows me to distinguish whether the code works in batch or interactive mode (via the console). It will be something like this:

if (interactive mode) {do this} else if (Batch mode) {do that}

Is there any way to achieve this? Thank you for your help.

+3
source share
1 answer

You can use the function interactive. For example, doing this from a terminal

Rscript -e 'cat(interactive())'

returns FALSEfor me, and when executed interactive()from my session, RStudio returns TRUE.

+2
source

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


All Articles