1

So I have code for a custom function in R, e.g. simply:

f <- function(x) return(x)

What I want to do is be able to call this function f as if it came with default R. That is, I don't want to have to source() the file containing the code to be able to use the function. Is there a way to accomplish this?

thelatemail
  • 91,185
  • 12
  • 128
  • 188

1 Answers1

3

What you are looking to do is documented extensively under ?Startup. Basically, you need to customize your Rprofile.site or .Rprofile to include the functions that you want available on startup. A simple guide can be found at the Quick-R site.

One thing to note: if you are commonly sharing code with others, you do need to remember what you've changed in your startup options and be sure that the relevant functions are also shared.

A5C1D2H2I1M1N2O1R2T1
  • 190,393
  • 28
  • 405
  • 485