Skip to content

what is best for scripting?

7 messages · Molins, Jordi, jim holtman, Gabor Grothendieck +4 more

#
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}}
#
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:
#
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:

  
    
#
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:
-------------- 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:
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. :-)
2 days later
#
Jos?? Matos wrote:

            
And if anyone wants to call Rserve[1] from Python then I've written some 
client code that does most of the useful[2] Rserve stuff.

If anyone wants to have a go with it (essentially, be a beta tester) let 
me know.

Baz

[1] http://stats.math.uni-augsburg.de/Rserve

[2] Well, useful to me.