If I define a function in an external file, I have to use source to load it in. So if I’m modifying a function, my process looks like:
- Make changes in file
- Source
- Test changes
- Back to 1
Is there any way to remove #2? E.g. in Octave it just dynamically searches your path to find the appropriate file every time you call a function.
No,
If you make changes to a function, you’re always going to have to reload it. However, as mentioned by commenters, there are other options when using RStudio, namely:
fix()Depending on the complexity of the function, I personally like
fix()because it immediately reloads the function and it’s great for making quick adjustments – but the caveat is that you have to remember to save your changes manually.When I’m troubleshooting, I generally use
fixand then copy-paste into my function file.The
devtoolspackage offers a range of simplification and streamlining for package development. Which, while it can also be useful for the purposes of reloading, seems to be outside of the scope of your question.