[R] R 1.8.1 - 1.9.0 incompatability: Underscore in syntactically valid names

Michael A. Miller mmiller3 at iupui.edu
Mon May 24 18:04:18 CEST 2004


>>>>> "Peter" == Peter Dalgaard <p.dalgaard at biostat.ku.dk> writes:

    > Gah! I could swear we discussed that particular issue
    > leading up to 1.9.x and had plans for a compatibility
    > option.

    > You might file a bug report at least for the docs, since
    > the example is clearly wrong...

Done.  

I tried to write some version dependencies into a sample code,
but I'm stumped by the fact that _ is not allowed before 1.9.0.
For example, suppose I have a data file, example.dat, like this: 

a b x   some_factor
1 1 0.4 orange
2 1 0.3 blue
1 1 0.2 dog
2 1 0.1 orange
1 2 0.4 blue
2 2 0.3 dog
1 2 0.2 orange
2 2 0.1 blue

To read and use this in a version independent way, I've tried this:

df <- read.table('example.dat',header=T)
if ( version['minor'] == "9.0" ) {
  plot(x ~ some_factor, data=df)
} else {
  plot(x ~ some.factor, data=df)
}


This fails in R 1.8.1, because some_factor throws a syntax error:

  > df <- read.table('example.dat',header=T)
  > if ( version['minor'] == "9.0" ) {
  + if ( version['minor'] == "9.0" ) {
  +   plot(x ~ some_factor, data=df)
  Error: syntax error
  > 

Ick.  Is there a known idiom for handling this sort of version
dependency in R?  I'm going to avoid R 1.9.x for now, and I
encourage any authors of contributing packages to do their best
to maintain backwards compatibility for those of us who cannot
make the switch quickly.

Mike

-- 
Michael A. Miller                               mmiller3 at iupui.edu
  Imaging Sciences, Department of Radiology, IU School of Medicine




More information about the R-help mailing list