I have a script with self-written functions (no plots). When I execute that script on the command line it takes ages to execute, but when I use
Since expressions are not executed at the top level, auto-printing is not done.
(...) the complete file is parsed before any of it is run
The issue is not
source() vs. command line code. Instead, it is an issue of how RStudio sends code from the source pane to the console.
When I copy the content of
Helperfunctions.R and run it in RGui (instead of RStudio), the code is executed with the same speed as when I use
source("Helperfunctions.R") in RStudio. The problem posed in the question compares the execution time of
source("Helperfunctions.R") with execution time of running its content in RStudio, in which case there is a huge discrepancy in execution time.
Apparently, lines of code always (?) require more execution time in RStudio than in RGui.
My understanding is that upon using
source("Helperfunctions.R") in the RStudio source pane, the code is not actually sent to the RStudio console (which would have been slow), but is actually executed directly in the