Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly does Source on Save mean or do?

Tags:

r

rstudio

Despite numerous searches, I can't seem to find a clear explanation as to what "Source on Save" means in RStudio.

I have tried ?source and the explanation there isn't clear, either.

As far as I can tell, it seems to run the script when I hit Save, but I don't understand the relevance/significance of it.

In simple terms, what exactly does Source on Save do and why would/should I use it?

like image 753
Mus Avatar asked Aug 02 '18 08:08

Mus


People also ask

How do I run ar codes?

To run an R command, put the cursor on the line of the command and then click the Run button at the top of the file window. Or just press CTRL-Enter.

How do I run an entire script in R?

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.

How do you save a session in RStudio?

You can save your script at any time (use Save in the File menu or the save shortcut, Ctrl+S or Cmd+S depending on your OS). After you've saved your work, close RStudio.

How do I write a script in R?

To start writing a new R script in RStudio, click File – New File – R Script. Shortcut! To create a new script in R, you can also use the command–shift–N shortcut on Mac.


1 Answers

This is kind of a shortcut to save and execute your code. You type something, save the script and it will be automatically sourced.

Very useful for short scripts but very annoying for time consuming longer scripts.

So sourcing is basically running each line of your file.

EDIT:
SO thinking of a scenario where this might be useful...

You developing a function which you will later put into a package... So you write this function already in an extra file but execute the function for testing in the command line... Normally, you have to execute the whole function again, when you changed something. While using "Source on Save" the function will be executed and you can use Ctrl + 2 to jump into command line and test the function directly.

Since I am working with R, my datasets are much bigger. But I am remembering starting coding in python and vi, I updated my setting in a way to execute the code on save, since these little scripts where done in less then 10 seconds...
So maybe it is just not standard to work with small datasets... But I can still recommend it, for development, to use only 10% of a normal dataset. It will speed up the graphics creation and a lot of other things as well. Test it with the complete dataset every now and then.

like image 166
drmariod Avatar answered Oct 20 '22 13:10

drmariod