开发者

Importing Functions into Current Namespace

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("/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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜