This is interesting. I'm on CentOS 6.9, R-3.4.2. I have a code, tmp.R
:
main<-function(){
a = 9
print(a) xyz
print("Should never get here")
}
When I run this, Rscript tmp.R
, I get
Error: unexpected symbol in:
" a = 9
print(a) xyz"
No traceback available
[1] "Should never get here"
Error: unexpected '}' in "}"
No traceback available
This is pretty confusing because I never actually called main()
. In fact, if I remove the syntax error
(3rd line becomes print(a)
), and I run it, there isn't any output. This is the expected behavior in my mind.
QUESTION : Why does R execute code in a script when a syntax error occurs, even when the code isn't explicitly called(!)?
EDIT : It turns out that this behavior seems to be due to having options(error=traceback)
being set in my .Rprofile
. This is undesirable behavior none the less. It would still be desirable to be able to get tracebacks when in interactive mode and not do this strange code execution in non-interactive mode.