[R] Several simple but hard tasks to do with R

Jim Lemon jim at bitwrit.com.au
Thu Aug 20 14:15:30 CEST 2009


Rakknar wrote:
>     Hello everybody. I've been learning R for about a month to do a
> econometric study and now i'm stuck with some problems to make R do the
> things I want. Here I give the list of things I wanna do from the most
> simple to the more complex (for me of course):
>
> 1. Make a log. I've been using Stata and there i have a great tool to
> register what the program do: the log file, wich it's a simple .txt file
> where Stata writes every output it makes (not graphics of course). When I
> wanted to make the same thing with R I started to use the function sink()
> but it only register the results of the commands (summaries for example) and
> not the commands itself, witch it's really uncomfortable because it's harder
> to find out to witch command that results come from.
>
>   
Hi Rakknar,
To echo what others have said, it is often easier to write a script (in 
STATA terms, a "do" file) of commands and then "source" the script. When 
it runs to your satisfaction, usually not the first time for me, there 
are several ways to store the output. Both the R2HTML and prettyR 
packages contain methods to store output as HTML files. You can store 
both the commands and output in the same file.
> 2. Saving objects in a .Rdata step by step. I want to save several
> regressions of interest in one .Rdata file. I want to save this results one
> by one. For example: make regression 1, save the result in the .Rdata file;
> then make the regression 2 and save the results in the same .Rdata file. I
> know I could make all the regressions and save the results all at once but
> for the kind of study I want to make It would be much useful this way. I've
> been using function save() but I only could save one result or all.
>
>   
You can save one object at a time if you want, and do it during a 
script. I usually save the primary data object after I have translated 
it from whatever format it came to me. You can save subsets of the data 
as different files and simply use "load" to read in the data you want. 
"load" can also signal if the data is not there, albeit in a fairly 
messy way.
> 3. Conditional reading. I want to run regressions conditional to the
> existence of a .Rdata file (the one I would be making in step two). The
> condition would be something like
> If "you find X.Rdata file" run regression with X.Rdata data else run
> regression from the 0.
>
> I hope I can find help here.
>
> Thanks!!
>   

Jim




More information about the R-help mailing list