I have a big looping script running in R-GUI and was curious if I can concurrently run other scripts in the same R-GUI session or can I open another session of R? Any suggestions would be great thanks.
RStudio Workbench (previously RStudio Server Pro) gives you the ability to open multiple concurrent sessions. Multiple concurrent sessions can be useful when you want to: Run multiple analyses in parallel. Keep multiple sessions open indefinitely.
In addition, in Rstudio you can run the entire script by pressing Ctrl + Shift + Enter without selecting any code. In addition, there is a shortcut to source the current script file ( Ctrl + Shift + s ), which runs the script without echoing each line.
Starting an R session The R programming can be done in two ways. We can either type the command lines on the screen inside an "R-session", or we can save the commands as a "script" file and execute the whole file inside R.
The RStudio IDE maintains a database of all commands which you have ever entered into the Console. You can browse and search this database using the History pane.
I often have several different instances of R running on my computer on different projects. While one is processing a script or doing a long run I can use a different one to work on another project.
While it is possible to have the same R session running multiple things concurrently (I have done this using the tcltk package) it is generally not advisable as the different projects could all access/change the same global environment which could mess things up. With multiple sessions they each have their own global environment (just be careful that they don't overwrite files if working from the same folder/directory).
There are also packages that will help with parallel processing which may be more what you are interested in. If each step of your loop runs independent of the others (step i+1 does not depend on the results of step i) and you have multiple processors (or multiple computers) then sometimes the parallel processing can help. See the HighPerformanceComputing task view on CRAN for descriptions of these packages.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With