[R] Saving an edited R function - RStudio and R

Sarah Goslee sarah.goslee at gmail.com
Wed Dec 31 17:49:56 CET 2014


Hi,

On Wed, Dec 31, 2014 at 11:24 AM, John Sorkin
<jsorkin at grecc.umaryland.edu> wrote:
> Windows 7
>
> Colleagues,
> I used the fix() function to edit an existing function when using RStudio. After editing the function, I am given the option to SAVE the modified function. I would like to know (1) where the modified function is stored (the save button does not have an option to specify where the modified function will be saved), and (2) how I can access the modified function in other RStudio or R sessions, and (3) how I can make the function accessible to R and RStudio sessions run on other computers.

I don't use RStudio, so I have no idea if it overwrites the base fix()
function. But if it does, this is the wrong place to ask about it, so
here's the base R answer.

fix() saves the edited function to your workspace. That is, if you
type ls() at an R prompt after running fix(), it will show your new
edited function. The usual methods for exporting something from R to
your hard disk will work, such as save() and load(). You could also
put your function into a text file myfun.R and use source() to read it
into R.

Once you've used one of these options to save your file to disk, it is
portable between R sessions and computers.

I find it much more convenient to use a text editor and source(),
personally, rather than fix(). That eases the transition into making
packages too.

Sarah


-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list