I have a script with self-written functions (no plots). When I copy-paste that script into the R-Studio console, it takes ages to execute, but when I use source("Helperfunctions.R") it doesn't take more than a second.
Question: Where does the difference in speed come from?
I am aware of two differences between running code via the source() function vs. entering code at the R-Studio console:
From ?source:
Since expressions are not executed at the top level, auto-printing is not done.
The way I understand this: source() will not plot graphs (unless made specific with e.g. print(plot)), while the R Studio console codes will always plot graphs. I'm sure this will affect the speed of execution to a certain degree, but this seems irrelevant in my case, because there are barely any plot calls.
And:
(...) the complete file is parsed before any of it is run
I have been working with R for a while now, but I'm not sure whether this relevant for the speed-issue I'm having. Is it possible that completely parsing all code "before any of it is run" speeds up the execution of my helper functions script by a factor of a hundred?
Edit: I'm using R version 3.2.3.
source("Helperfunctions.R"), this is quick. However, when I copy the content of Helperfunctions.R and execute the code directly, it takes ages for the code to run. Does that help, @Roland ? - KenHBSRshell? If no, then this is definitely RStudio (where I also observed performance issues executing lines of code from the editor). - Martin NyoltRshell is certainly much (!!) faster than RStudio. Please post it as a solution. Any chance there is a simple answer as to why RStudio is so slow in this case? Are there cases in which RStudio is actually faster? - KenHBS