[R] R as a programming language

Jan T. Kim jtk at cmp.uea.ac.uk
Thu Nov 8 21:16:01 CET 2007


On Thu, Nov 08, 2007 at 01:35:34PM -0500, Duncan Murdoch wrote:
> On 11/8/2007 1:26 PM, Barry Rowlingson wrote:
> > hadley wickham wrote:
> > 
> >> You're assuming an automatic cast from numbers into strings?  What if
> >> a + "4" threw an error?
> > 
> >   What's wrong with commas anyway when using cat():
> > 
> >   > cat("x is ",x,' and y is ',y,'\n',sep='')
> >   x is 1 and y is 2
> 
> Nothing wrong when using cat(), but we sometimes need to compute strings 
> when we aren't using cat().
> 
> >   and there's always sprintf() for those moments when you want neat 
> > formatting.
> 
> That's good when you want good control over the formatting, but it 
> doesn't tend to be all that readable, with the variables all listed at 
> the end, instead of in between the bits of string.

I'm probably saying the obvious but paste() can be used like cat() in
the example above to obtain a string rather than to output it.

Personally, I've come to prefer the printf style with the format string
and the data to be formatted nicely separated, but perhaps I've just
been programming in C / Python / Java too long...

> >   Is it just me who thinks it's odd that in a language that is umpteen 
> > years old we are still discussing the fundamentals of what essentially 
> > makes up the 'hello world' example?
> 
> Maybe.

It seems to me that there are good reasons to discuss issues about the
language (from time to time, anyway).

What I'd like to see in R are:

    (1) References. These have a more fundamental role than just saving
      memory (by avoiding unnecessary copying of parameter values etc.)
      in enabling programmers to achieve a higher level of representational
      consistency: Each object in the problem domain should ideally
      be represented by one object in a program, and that is currently
      difficult and sometimes impossible to realise in R -- it's not
      possible to distinguish equality and identity, as e.g. in Java
      ("equals()" vs "==") or Python ("==" vs "is").

    (2) More process and I/O facilities, specifically I'd like forking and
      something like a "functionconnection" which works like a
      textconnection but obtains input from / feeds output to a function.
      This would allow running an external process that receives input
      *and* provides output to R -- currently, pipes allow either one
      or the other, but not both.

With these two, I'd be quite inclined to use R as my primary scripting
language. (I tried to get there a while ago and wrote a "filterpipe"
patch to achieve (2), currently I work use a mix of Python and R).

Best regards, Jan
-- 
 +- Jan T. Kim -------------------------------------------------------+
 |             email: jtk at cmp.uea.ac.uk                               |
 |             WWW:   http://www.cmp.uea.ac.uk/people/jtk             |
 *-----=<  hierarchical systems are for files, not for humans  >=-----*



More information about the R-help mailing list