I am using R in Windows. I see that I will have to use batch processes with R. I will have to read and write text files, and run some R code; probably some external code too. I have never done scripting. Is there any document that explains simple steps with examples? I also have heard that Python is a good scripting language. Is it worth the effort? (I do not have too much free time, so if I could do without, much better ...). Has anybody strong opinions on that? Past experiences? Thank you! Jordi -------------------------------------------------------------------------------- The information contained herein is confidential and is inte...{{dropped}}
A lot is personal preference. I use Perl since it is very good at doing any of the preprocessing that I need to setup data for R; e.g., reading a text file, extracting the data and then setting it up in a format for R. I can then invoke R from the script. Here is a sample of come Perl code that actually calls some other Perl scripts and then invokes R (this script logs onto a UNIX system, extracts some data, preprocesses with other Perl scripts and then calls R with a set of commands with the appropriate substitutions: use Net::Telnet; my $t = Net::Telnet->new(Timeout => 900, Host => $ftpName); #setup the host $t->login($user, $password); #login print STDERR $t->cmd("acctcom $perfDir/pacct.$yesterday>/tmp/pacct.$yesterday.$hostname");# # create the FTP commands to xfer the data # my $ftp = Net::FTP->new($ftpName) or die "FTP new"; $ftp->login($user, $password) or die 'login'; $ftp->cwd($perfDir) or die 'cwd'; ftpGet($ftp, "SRVL_serval_${yesterday}.longps", "longps.$hostname.$yesterday"); ftpGet($ftp, "SRVL_serval_${yesterday}.sar", "sar.$hostname.$yesterday"); ftpGet($ftp, "/tmp/pacct.$yesterday.$hostname", "pacct.$yesterday.$hostname"); ftpGet($ftp, "/u01/WIData/audit/user.log", "user.log"); ftpGet($ftp, "/u01/WIData/audit/userdet.log", "userdet.log"); $ftp->quit(); system("perl /perf/bin/sarextr.pl sar.$hostname.$yesterday"); system("perl /perf/bin/driveuse.pl sar.$hostname.$yesterday"); system("awk -f /perf/bin/longps.awk longps.$hostname.$yesterday>ps.$hostname.$yesterday");system("perl /perf/bin/psextrV2.pl ps.$hostname.$yesterday"); system("perl /perf/bin/sumprocs.pl ps.$hostname.$yesterday.cpu"); system("perl /perf/bin/userdet.pl userdet.log >userdet.txt"); system("perl /perf/bin/acct-extr.pl pacct.$yesterday.$hostname"); open RBATCH, ">rcmds.txt" or die "RBATCH"; # # create the R command file # print RBATCH <<EOF; setwd('/perf/data') load('/perf/data/.RData') # restore environment my.stats('start') postscript(file="proc.$hostname.$yesterday.ps", width=10, height=7.5, horizontal=TRUE, family="Courier") plot.procs("ps.$hostname.$yesterday") plot.sar("sar.$hostname.$yesterday.srx") source('/perf/bin/Accounting Functions.R') acct.log <- acct.read.file("pacct.${yesterday}.${hostname}.pacct") acct.proc.cpu(acct.log, sar.overlay=c("sar.$hostname.$yesterday.srx",2)) acct.cpu.polygon(acct.log[acct.log\$cmd=='wiqt', ]) acct.count.polygon(acct.log, y.limit=500) plot.srx.file("sar.$hostname.$yesterday.srx", post.script=F, layout=c(5,5)) dev.off() my.stats('done') EOF print STDERR $t->cmd("rm /tmp/pacct.$yesterday.$hostname"); $t->close(); close RBATCH; system("\"C:/Program Files/R/rw2010/bin/Rterm.exe\" --max-mem-size=512M --no-save <rcmds.txt >$hostname.$yesterday.batch"); On 12/2/05, Molins, Jordi <Jordi.Molins@drkw.com> wrote:> > > I am using R in Windows. I see that I will have to use batch processes > with > R. I will have to read and write text files, and run some R code; probably > some external code too. I have never done scripting. Is there any document > that explains simple steps with examples? I also have heard that Python is > a > good scripting language. Is it worth the effort? (I do not have too much > free time, so if I could do without, much better ...). > > Has anybody strong opinions on that? Past experiences? > > Thank you! > > Jordi > > > > > -------------------------------------------------------------------------------- > The information contained herein is confidential and is inte...{{dropped}} > > ______________________________________________ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >-- Jim Holtman Cincinnati, OH +1 513 247 0281 What the problem you are trying to solve? [[alternative HTML version deleted]]
I do nearly all my scripting in R if its part of an R project. That keeps things simple since everything is in one language. See ?BATCH, ?commandArgs, ?readLines, ?system, ?grep, ?regex (and commands pointed to by it). If your script deals with XML, see the R XML package. If R is not involved I may use R anyways for scripting since its powerful and I already use it for other tasks but if I don't use R then I will use awk/gawk because its simple and fast. If its important to eliminate all external dependencies I will use Windows batch (or jscript/javascript) as in http://cran.r-project.org/contrib/extra/batchfiles/ I don't find I rarely need anything beyond that. I used to use perl in my pre-R days but since using R don't find I need it any more. I have played with python and it looks very nice but for most R problems its probably also unnecessary. On 12/2/05, Molins, Jordi <Jordi.Molins at drkw.com> wrote:> > I am using R in Windows. I see that I will have to use batch processes with > R. I will have to read and write text files, and run some R code; probably > some external code too. I have never done scripting. Is there any document > that explains simple steps with examples? I also have heard that Python is a > good scripting language. Is it worth the effort? (I do not have too much > free time, so if I could do without, much better ...). > > Has anybody strong opinions on that? Past experiences? > > Thank you! > > Jordi > > > > -------------------------------------------------------------------------------- > The information contained herein is confidential and is inte...{{dropped}} > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >
Using R itself has the advantage that you won't need to learn a new language. You may even learn R better as a result. Using Python could also work well. I have found it worth learning, at least the basics. There a wider range of documentation (books) available for Python than for R, and that may be helpful to you. Its syntax is less fanciful and more clean and transparent than the syntax of Perl. Its arrays start from zero, which can promote errors for those used to languages where arrays start from 1. Python is free, and so you can download it, try a few examples, and see if you like it. The download includes Idle, a graphical front end similar in concept to Rgui. Either way, good luck! I hope that is helpful. MHP on 12/2/2005 3:37 AM Molins, Jordi said the following:>I am using R in Windows. I see that I will have to use batch processes with >R. I will have to read and write text files, and run some R code; probably >some external code too. I have never done scripting. Is there any document >that explains simple steps with examples? I also have heard that Python is a >good scripting language. Is it worth the effort? (I do not have too much >free time, so if I could do without, much better ...). > >Has anybody strong opinions on that? Past experiences? > >Thank you! > >Jordi > > > >-------------------------------------------------------------------------------- >The information contained herein is confidential and is inte...{{dropped}} > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > >-- Michael Prager, Ph.D. Population Dynamics Team, NMFS SE Fisheries Science Center NOAA Center for Coastal Fisheries and Habitat Research Beaufort, North Carolina 28516 http://shrimp.ccfhrb.noaa.gov/~mprager/ Opinions expressed are personal, not official. No government endorsement of any product is made or implied.
As I get more familiar with R I tend to find the need for massaging data with other scripts decreasing. I still use python as a front end to some R tasks and it is a great language to have in your personal arsenal (as is R). The kind of decision making process for me goes something like: o If R can read the data directly then use R. I am pleasantly surprised at R in this regard. o If Python (or other scripting tool) already has bindings for dataset that you want, consider using Python. Eg I extract software development metrics from Perforce with python for plotting in R. o If the data set has a complex grammar, choose a tool with support for grammar compilers (I use and recommend pyparsing but there are dozens of choices). Actually I didn't check if there is a grammar compiler for R. Someone mentioned BeautifulSoup not long ago for extracting stuff from broken HTML. I have used this also with some success for extracting deeply nested tables in poorly written HTML. I usually dump data from Python to R in CSV format. I call R scripts from Python and about the only trick I use here is to read in an R script template and perform string variable expansion (interpolation in Perl) before sending it to an R process. See attached for example. For various reasons I have not used the R-Python bindings. cheers Molins, Jordi wrote:> I am using R in Windows. I see that I will have to use batch processes with > R. I will have to read and write text files, and run some R code; probably > some external code too. I have never done scripting. Is there any document > that explains simple steps with examples? I also have heard that Python is a > good scripting language. Is it worth the effort? (I do not have too much > free time, so if I could do without, much better ...). > > Has anybody strong opinions on that? Past experiences? > > Thank you! > > Jordi > > > > -------------------------------------------------------------------------------- > The information contained herein is confidential and is inte...{{dropped}} > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >-------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: R.py Url: https://stat.ethz.ch/pipermail/r-help/attachments/20051203/efa65ed2/R.pl
On 02/12/05, paul sorenson <sourceforge at metrak.com> wrote:> > I usually dump data from Python to R in CSV format. I call R scripts > from Python and about the only trick I use here is to read in an R > script template and perform string variable expansion (interpolation in > Perl) before sending it to an R process. See attached for example. For > various reasons I have not used the R-Python bindings.In this case I prefer to use rpy (look for it in sourceforge), it allow to call R directly from python, with the main advantage that the resulting objects are really python objects, and vice-versa calling R with python objects will convert them to R objects. It works quite well for me. :-)> cheers