You could use the saveHistory command to save the history of commands that you have written to a file, then read that into a variable using the scan function, then do the save or save.image to save everything.
A different approach would be to save transcripts of your session that would show the commands run and the output created, on option for doing this is to run R inside of ESS/emacs, another option is the txtStart function in the TeachingDemos package. You could also use the addTaskCallback function to add a task callback that adds each command (well the successful ones, errors don't trigger the callbacks) to a text vector, then this text vector would be saved in .Rdata when doing save.image() -----Original Message----- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Michael Sent: Saturday, January 21, 2012 5:25 PM To: r-help Subject: [R] how to save the R script itself into a rData file? Hi all, As a part of work flow, I do a lot of experiments and save all my results into rData file... i.e. at the end of all my experiments, I do "save.image("experiment_name_with_series_number.rData")"... However, some times even with the rData files, I cannot remember the context where these data files were generated. Of course, I can make the R data file names and the R script file names the same, so that whenever I see a data file, I will be able to track down to how the result file was generated. This is fine. But sometimes a bunch of different results rData files were generated simply from varying a parameter in the same R script file. It's kind of messy to save different R script files with different names when only parameters are different, and not to say if there are a bunch of parameters that need to be put into file names... Lets say I changed the parameters x to 0.123, y to -0.456, z to -999.99 Then I have to save the R script file as "Experiment_001_x=0.123_y=-0.456_z=-999.99.r" and the result file as "Experiment_001_x=0.123_y=-0.456_z=-999.99.rData" ... This is kind of messy, isn't it? Is there a way to save the whole script file (i.e. the context where the data file is generated) into the rData file? It cannot be the file location and/or file name of the R script file; it needs to be the whole content of the file... to prevent the parameters change .. i.e. the same R script file but with different combinations of parameters... How to do that? Any good tricks? Thanks a lot! [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list 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. ______________________________________________ R-help@r-project.org mailing list 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.