Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically "sourcing" function on change

Tags:

r

While I am writing .R functions I constantly need to manually write source("funcname.r") to get the changes reflected in the workspace. I am sure it must be possible to do this automatically. So what I would like would be just to make changes in my function, save the function and be able to use the new function in R workspace without manually "sourcing" this function. How can I do that?

UPDATE: I know about selecting appropriate lines of code and pressing CTRL+R in R Editor (RGui) or using Notepad++ and executing the lines into R. But this approach has a disadvantage of making my workspace console "muddled". I would like to stop this practice if at all possible.

like image 231
Grega Kešpret Avatar asked Dec 28 '22 23:12

Grega Kešpret


2 Answers

You can use R studio which has a source on save option.

like image 189
Etienne Low-Décarie Avatar answered Dec 31 '22 02:12

Etienne Low-Décarie


If you are prepared to package your functions into a package, you may enjoy exploring Hadley's devtools package. This provides a suite of tools to write, test and document packages.

https://github.com/hadley/devtools

This approach offer many advantages, but mainly reloading the package with a minimum of retyping.

You will still have to type load_all("yourpackage") but I find this small amount of typing is small beer compared to the advantages of devtools.

For additional information, including how to setup devtools, have a look at https://github.com/hadley/devtools/wiki/development

like image 23
Andrie Avatar answered Dec 31 '22 02:12

Andrie