Is there a straightforward way to turn the functions of a .RData file into a normal code file (.R)?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Check out ?dump
. For example:
newEnv <- new.env()
load("myFunctions.Rdata", newEnv)
dump(c(lsf.str(newEnv)), file="normalCodeFile.R", envir=newEnv)
You may also be interested in ?prompt
(which creates documentation files for objects) and / or ?package.skeleton
.
回答2:
This recent blog post addresses a basically the same problem:
http://www.r-statistics.com/2010/09/dumping-functions-from-the-global-environment-into-an-r-script-file/
回答3:
There's another solution from another post using sink
sink(file="Function.R")
Function # The object
sink()