9

Is there a straightforward way to turn the functions of a .RData file into a normal code file (.R)?

zx8754
  • 52,746
  • 12
  • 114
  • 209
Christian
  • 25,249
  • 40
  • 134
  • 225

3 Answers3

16

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.

Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418
  • Great update Joshua. I updated my post to include your solution as well. http://www.r-statistics.com/2010/09/dumping-functions-from-the-global-environment-into-an-r-script-file/ – Tal Galili Oct 02 '10 at 07:07
3

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/

Aaron
  • 816
  • 7
  • 4
0

There's another solution from another post using sink

sink(file="Function.R")
Function # The object
sink()
Community
  • 1
  • 1