See ?load, but you may be confused. Strictly speaking, there is no code in an .Rdata file, only a (typically binary, but possibly ascii) representation of objects, usually as produced by ?save. Of course, functions are also objects, so that if you load a file with functions, the function code is available. You can save and load command histories via ?savehistory, which, like ?save and ?load can usually be accessed through any GUI interface that you are using. Warning: I believe the above is correct, but I may be wrong in at least some details, so give others a chance to reply and possibly correct. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Wed, Oct 27, 2021 at 10:18 AM Bogdan Tanasa <tanasa at gmail.com> wrote:> Dear all, would you please advice : > > I have an Rdata file, what is the way to print the R code that has been > used inside the Rdata file ? > > thank you, > > Bogdan > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
Sounds right, though the OP appears to be assuming that the code used to generate the data objects in the file will also be there, and we need to be more definitive about that: it is not. Depending how the code was constructed, there may be useful information in the functions that were stored in the environment from which the save file was created, but this is not in any way guaranteed to be useful. In particular, there is no trace IN the RData file of which packages need to be loaded in order to access the objects stored in that RData file. This is one of the reasons depending on RData files for archiving work is not advisable... and why putting code in R scripts or Sweave/knitr-based literate programming files IS recommended. On October 27, 2021 10:47:14 AM PDT, Bert Gunter <bgunter.4567 at gmail.com> wrote:>See ?load, but you may be confused. Strictly speaking, there is no code in >an .Rdata file, only a (typically binary, but possibly ascii) >representation of objects, usually as produced by ?save. Of course, >functions are also objects, so that if you load a file with functions, the >function code is available. > >You can save and load command histories via ?savehistory, which, like ?save >and ?load can usually be accessed through any GUI interface that you are >using. > >Warning: I believe the above is correct, but I may be wrong in at least >some details, so give others a chance to reply and possibly correct. > >Cheers, >Bert > >Bert Gunter > >"The trouble with having an open mind is that people keep coming along and >sticking things into it." >-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > >On Wed, Oct 27, 2021 at 10:18 AM Bogdan Tanasa <tanasa at gmail.com> wrote: > >> Dear all, would you please advice : >> >> I have an Rdata file, what is the way to print the R code that has been >> used inside the Rdata file ? >> >> thank you, >> >> Bogdan >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > [[alternative HTML version deleted]] > >______________________________________________ >R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.-- Sent from my phone. Please excuse my brevity.
>>>>> Bert Gunter >>>>> on Wed, 27 Oct 2021 10:47:14 -0700 writes:> See ?load, but you may be confused. Strictly speaking, there is no code in > an .Rdata file, only a (typically binary, but possibly ascii) > representation of objects, usually as produced by ?save. Of course, > functions are also objects, so that if you load a file with functions, the > function code is available. > You can save and load command histories via ?savehistory, which, like ?save > and ?load can usually be accessed through any GUI interface that you are > using. > Warning: I believe the above is correct, but I may be wrong in at least > some details, so give others a chance to reply and possibly correct. > Cheers, > Bert > Bert Gunter In spite of really not recommending to work with .RData but rather with R *scripts* (or R Sweave / R markdown documents), an often forgotten considerably more flexible and in that sense better alternative to load() in such situations is attach() which creates an environment in which the objects are loaded and attaches that to the search() path. Example (from my current R console):> save.image() # creates .RData > attach(".RData") > ls.str(pos=2)logi : Named logi [1:3] FALSE NA TRUE Mlibrary : function (pkg, lib = NULL, check64.32 = TRUE, ...) ncF : int [1:5, 1:3] 5 6 2 1 15 5 6 2 1 15 ... nchars : function (x, ...) ncT : int [1:5, 1:3] 5 6 NA 1 15 5 6 NA 1 15 ... x : chr [1:5] "asfef" "qwerty" NA "b" "stuff.blah.yech">So, indeed, ls.str() comes handy as well.. Best, Martin