Full_Name: Mike Miller Version: 1.9.0 OS: win2000 Submission from: (NULL) (134.68.121.109) The docs for make.names imply that the result of make.names(c("a and b", "a_and_b"), unique=TRUE) should be "a.and.b" "a.and.b.1" when it is actually "a.and.b" "a_and_b" The docs do not reflect this very major change in behavior from 1.8.x to 1.9.0. This change causes numerous R codes to fail in senarios like the following. 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 to write version-aware code, but this is difficult as '_' is not syntactically valid prior to R 1.9.0. If it were, the following code might work. Of course, if '_' were allowed, this issue would not be be a problem. 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) }
Example output in comment is now corrected in R-patched. What has the rest to do with a bug report? On Mon, 24 May 2004 mmiller3@iupui.edu wrote:> Full_Name: Mike Miller > Version: 1.9.0 > OS: win2000 > Submission from: (NULL) (134.68.121.109) > > > The docs for make.names imply that the result of > > make.names(c("a and b", "a_and_b"), unique=TRUE) > > should be > > "a.and.b" "a.and.b.1" > > when it is actually > > "a.and.b" "a_and_b" > > The docs do not reflect this very major change in behavior from 1.8.x to 1.9.0. > This change causes numerous R codes to fail in senarios like the following. > 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 to write > version-aware code, but this is difficult as '_' is not syntactically valid > prior to R 1.9.0. If it were, the following code might work. Of course, if '_' > were allowed, this issue would not be be a problem. > > 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) > } > > ______________________________________________ > R-devel@stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-devel > >-- Brian D. Ripley, ripley@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Prof Brian Ripley <ripley@stats.ox.ac.uk> writes:> Example output in comment is now corrected in R-patched. > What has the rest to do with a bug report?He's hoping (with some reason) that the change of behaviour was the bug. I seem to recall some internal discussion of the effect, but not whether it just got forgotten or whether you might as well just do gsub(...something...) on the names of the dataframe. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907
Peter Dalgaard <p.dalgaard@biostat.ku.dk> writes:> Prof Brian Ripley <ripley@stats.ox.ac.uk> writes: > > > Example output in comment is now corrected in R-patched. > > What has the rest to do with a bug report? > > He's hoping (with some reason) that the change of behaviour was the > bug. I seem to recall some internal discussion of the effect, but not > whether it just got forgotten or whether you might as well just do > gsub(...something...) on the names of the dataframe.Apparently, the latter was the case. It is quite easy to fix the names after reading, and adding a compatibility feature would be kludgy, and not relieving you of changing the old code anyway. I have updated the docs (for 1.9.1) with some more specific instructions about what to do: diff -r1.9.4.1 make.names.Rd 31a32,36> \note{ > Prior to version 1.9.0, underscores were not valid in variable names, > and code that relies on them being converted to dots will no longer > work. The simplest workaround is to use \code{gsub("_", ".", > names)}. > }diff -r1.50 read.table.Rd 189a190,196> > Prior to version 1.9.0, underscores were not valid in variable names, > and code that relies on them being converted to dots will no longer > work. The simplest workaround is to use > \code{names(d) <- gsub("_", ".", names(d))}, > or, avoiding the (small) risk of creating duplicate names, > \code{names(d) <- make.names(gsub("_", ".", names(d)), > unique=TRUE)}.-- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907