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. 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. 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!! -- View this message in context: http://www.nabble.com/Several-simple-but-hard-tasks-to-do-with-R-tp25052563p25052563.html Sent from the R help mailing list archive at Nabble.com.
Rakknar: I believe your subject line characterization reflects your ignorance of R, rather than its inherent limitations. 1. logs. help.search("history") and ?savehistory shows you that R does exactly what you want very easily (depending on the platform, which contrary to the posting guide's request, you did not tell us). 2. saving data. ?save would show you how this can be trivially done manually. ?addTaskCallback , an admittedly more sophisticated and less well-known approach, would show you how this can be done simply and automatically. 3. Conditional execution. R is a programming language! It is straightforward to write a little program that does exactly what you want using R's built in file system functionality. ?files will tell you what's available; I believe file.exists() is what you want in a construct like if(file.exists(yourfile.rdata))lm(...,data = read(yourfile.rdata)) So unless I have misconstrued your queries, I think with a little more digging into the R docs (or supporting books, most of which are listed on CRAN), you would find that contrary to your accusation, all these tasks are indeed quite simple in R -- and that R's developers anticipated them years ago. Hope this clarifies... Bert Gunter Genentech Nonclinical Biostatisics -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Rakknar Sent: Wednesday, August 19, 2009 2:52 PM To: r-help at r-project.org Subject: [R] Several simple but hard tasks to do with R 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. 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. 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!! -- View this message in context: http://www.nabble.com/Several-simple-but-hard-tasks-to-do-with-R-tp25052563p 25052563.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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.
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, I would recommend not using the command line as such too much. Making a script on your harddrive and always working from that seems a better to me. If you have some data on your harddrive (csv for example) you can write a script that takes that data and produces your results (graphs, lm's etc). This ensures that you can always later see how you have done your analysis, and redo if necessary. See also this e-mail on R-help http://www.nabble.com/PowerCut-Killed-R---is-my-code-retrievable--td25052662.html#a25052662. cheers and hope this helps, Paul> 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. > > 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!! >-- Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +3130 274 3113 Mon-Tue Phone: +3130 253 5773 Wed-Fri http://intamap.geo.uu.nl/~paul
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
Ottorino-Luca Pantani
2009-Aug-20 15:18 UTC
[R] Several simple but hard tasks to do with R
Rakknar ha scritto:> 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. > >A possible workaround could be: sink("ouputfile.txt") as.character("rnorm(5, mean = 0, sd = 1)") rnorm(5, mean = 0, sd = 1) sink() I know, it is not elegant, and a bit repetitive, but it could help. 8rino