Automatic "search" function when changing

When writing .R functions, I constantly need to manually write the source ("funcname.r") to get the changes reflected in the workspace. I am sure it is possible to do this automatically. Therefore, I would just like to make changes to my function, save the function and use the new function in the R workspace without manually “searching” for this function. How can i do this?

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

+4
source share
5 answers

If you are ready to pack your features in a package, you can check out the Hadley devtools package. It provides a set of tools for recording, testing and documenting packages.

https://github.com/hadley/devtools

This approach has many advantages, but basically reloads the package with minimal redialing.

You still have to type load_all ("yourpackage"), but I find that this is a small amount of input - this is a small beer compared to the benefits of devtools.

For more information, including how to set up devtools, see https://github.com/hadley/devtools/wiki/development

+2
source

You can use studio R , which has a source with persistence.

+3
source

If you use Eclipse + StatET, you can press CTRL + R + S, which will save your script and be its source. As close to automatic as possible.

+2
source

This is probably not possible (automatic detection of disk changes without intervention or the launch of at least one line).

R must be read in the memory function, so the change on the disk will not be reflected in the workspace without rebooting your functions.

If you are developing R functions, some of the clutter during your development process is probably inevitable, but maybe I could suggest you try creating an R package to accommodate your functions?

This has the advantage that you can reliably document your functions using lazy loading to immediately access your functions / datasets without searching for them.

Do not be afraid to make a package easily with package.skeleton () and you do not need to go for CRAN, but it can be for your personal use without distribution! Just have fun!

Try to make some mess during development, knowing that you are working on your goal and fighting a good fight for organizing your code and documentation!

We are only imperfect people in an imperfect world, but we mean well!

+1
source

If you can get a text editor to run a system command after saving the file, you can use something like AutoIt (on Windows) or a batch script (on a UNIX derivative) to transfer a call to the source file from all executable copies of R. But this is a hell of a lot of work for not very big benefits.

However, I think it is much more likely that it will be event driven at the end of the text editor, since R constantly checks for updates (or somehow interacts with the update system for event-message-events).

+1
source

Source: https://habr.com/ru/post/1345942/


All Articles