Reputation: 11762
In RStudio, is there a way to stop the execution of your script in case you execute a selection?
My problem is that most of "my users" love to select the whole script and click "Run the current line or selection (Ctrl+Enter)" instead of sourcing the script.
I have some stop
commands inside my script, to stop execution and warn the user what is wrong. But selecting everything and running, the script will just continue. Is there a way around this, to force the ongoing execution to stop?
just a minimal example:
if(TRUE) stop('stop here')
print('continue')
I guess it is easier to explain people not to execute the selection but sourcing, but this anyhow often happens in my working group.
Upvotes: 2
Views: 340
Reputation: 7871
You can add {}
for all project like :
{if(TRUE) stop('stop here')
print('continue')
}
than Ctrl+A Ctrl+Enter
give you
> {if(TRUE)
+ stop('stop here')
+
+ print('continue')
+ }
Error: stop here
Upvotes: 2