[R] how to save the R script itself into a rData file?

jim holtman jholtman at gmail.com
Sun Jan 22 02:39:38 CET 2012


The what you can do is that the 'main' R script just setups up the
parameters and then calls functions (or sources in another R script).
What you will be doing by the process I described is saving just the
short R script that has all of your parameters.  Does this solve your
problem?

As a second option, use 'readLines' to read in your 'parameter' file
that was passed in into a character object.  This will be saved in the
RData file and then when you read it back in, you can then look at
this character object to see what the parameters were.

On Sat, Jan 21, 2012 at 8:25 PM, Michael <comtech.usa at gmail.com> wrote:
> 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 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.



More information about the R-help mailing list