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]]
Create a function that you can pass the name of the R script to run and the fileName you want applied to the output files. First copy the R script to a file with the 'fileName.R' that as passed in, then 'source' the file to execute it. Change your script to also use the 'fileName' to create the RData file. That will create two files (source and data) that should allow you to recreate your data. On Sat, Jan 21, 2012 at 7:24 PM, Michael <comtech.usa at gmail.com> wrote:> 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 at 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.-- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it.
I don't want to save separate script files with merely parameter changes... This is a 1-to-multiple mapping problem: I have one script file, but varying parameters leads to multiple rData files... If I could save the script file content (with the correct parameter combinations) into the same rData file, everything would be self-containing and self-explainatory... On Sat, Jan 21, 2012 at 6:24 PM, Michael <comtech.usa@gmail.com> wrote:> 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]]
thx but then how do I save a snapshot of all the variables at the end of the function? We need the entire snapshot in case not to forget important items... Also when I say varying parameters, in fact certain code of the program can vary too in addition to the parameters. Any more thoughts? I can of course read the whole script file as a variable but that ddestroys the formatting and make the variablenot understandable... Any more thoughts? Thanks a lot! On Jan 21, 2012 9:41 PM, "Florent D." <flodel@gmail.com> wrote: [[alternative HTML version deleted]]
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-bounces at r-project.org [mailto:r-help-bounces at 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 at 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.