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

jim holtman jholtman at gmail.com
Sun Jan 22 06:26:25 CET 2012


I think you need to restate the problem that you are trying to solve.
You originally said it was just some parameters, but now you say
'code' is being changed.  Also now you indicate that you want the
formating to be saved.  This would indicate that you want to save the
entire R script, not just the 'parameters'.  If you want this in the
'save.image' that you are going to create, then write a function that
will save the script in an object using 'readLines'; this will
preserve the formatting if you want to print it would.  You can then
run the script and 'save.image' the entire global area that should
give you what you want.

Now exactly what do you want to do with the 'script' that has been
saved?  You can easily rerun it (simple way is to use 'writeLines' to
write it to a tempory file and then source it in; you could also
'edit' it in the temporary file).

So can you give some more definition of the problem if the above
solution will not work.  It does save the original script with the
formatting preserved.

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



-- 
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