tags:

views:

80

answers:

1

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.

+4  A: 

Use the source() command. In your case:

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).

Shane
that's exactly what i was looking for, though in fact, the package.skeleton(), which i wasn't aware of prior to your Answer, was far easier than i thought and I actually used that in the end. Thanks!
doug