Let's say I have an R source file comprised of some functions, doesn't matter what they are, e.g.,
fnx = function(x){(x - mean(x))/sd(x)}
I would like to be able to access them in my current R session (without typing them in obviously). It would be nice if library("/path/to/file/my_fn_lib1.r") worked, as "import" works in Python, but it doesn't. One obvious solution is to create an R Package, but i want to avoid that overhead just to import a few functions.
Use the source() command. In your case:
source()
source("/path/to/file/my_fn_lib1.r")
Incidentally, creating a package is fairly easy with the package.skeleton() function (if you're planning to reuse this frequently).
package.skeleton()
1.4m articles
1.4m replys
5 comments
57.0k users