Hello there, I just upgraded to R 2.15 (from R 2.12) on a Windows XP machine and noticed some puzzling behaviour (that in my opinion did not exist in R 2.12). It is possible now to call objects without spelling out the full object name. R now seems to use that (unique) object which shares the same beginning of the called object, even though the originally called object might not even exist. This is quite awkwardly described, but perhaps you know what I'm talking about? Let's say I'm using the Mroz data supplied with the car package: require(car) data(Mroz) there is no variable called "w" in that dataframe, but calling summary(Mroz$w) #### Mroz$w does not exist does not return any error but instead gives the same result as summary(Mroz$wc) ##### exists in Mroz I find this behaviour *very* undesirable. Is there any way to switch it off? Best, Irene
On Jul 6, 2012, at 15:36 , knallgrau at gmx.com wrote:> Hello there, > > I just upgraded to R 2.15 (from R 2.12) on a Windows XP machine and noticed some puzzling behaviour (that in my opinion did not exist in R 2.12). > > It is possible now to call objects without spelling out the full object name. R now seems to use that (unique) object which shares the same beginning of the called object, even though the originally called object might not even exist. > > This is quite awkwardly described, but perhaps you know what I'm talking about? > > Let's say I'm using the Mroz data supplied with the car package: > > require(car) > data(Mroz) > > there is no variable called "w" in that dataframe, but calling > > summary(Mroz$w) #### Mroz$w does not exist > > does not return any error but instead gives the same result as > > summary(Mroz$wc) ##### exists in Mroz > > > I find this behaviour *very* undesirable. Is there any way to switch it off?It's called partial matching and has been around since the King of Diamonds was a Knave (as the local saying goes). The feature has long since lost the love of its inventors, but it has been considered impossible to remove because of all the usages like chisq.test(M)$obs. Easiest workaround is to use Mroz[["wc"]], see ?Extract for more info. -- Peter Dalgaard, Professor Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
This has always been how the $ operator has worked. See ?"[[", and use that operator directly if you want exact matching. --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. knallgrau at gmx.com wrote:>Hello there, > >I just upgraded to R 2.15 (from R 2.12) on a Windows XP machine and >noticed some puzzling behaviour (that in my opinion did not exist in R >2.12). > >It is possible now to call objects without spelling out the full object >name. R now seems to use that (unique) object which shares the same >beginning of the called object, even though the originally called >object might not even exist. > >This is quite awkwardly described, but perhaps you know what I'm >talking about? > >Let's say I'm using the Mroz data supplied with the car package: > >require(car) >data(Mroz) > >there is no variable called "w" in that dataframe, but calling > >summary(Mroz$w) #### Mroz$w does not exist > >does not return any error but instead gives the same result as > >summary(Mroz$wc) ##### exists in Mroz > > >I find this behaviour *very* undesirable. Is there any way to switch it >off? > >Best, >Irene > >______________________________________________ >R-help at r-project.org mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.
On Jul 6, 2012, at 9:36 AM, knallgrau at gmx.com wrote:> Hello there, > > I just upgraded to R 2.15 (from R 2.12) on a Windows XP machine and > noticed some puzzling behaviour (that in my opinion did not exist in > R 2.12). > > It is possible now to call objects without spelling out the full > object name. R now seems to use that (unique) object which shares > the same beginning of the called object, even though the originally > called object might not even exist. > > This is quite awkwardly described, but perhaps you know what I'm > talking about? > > Let's say I'm using the Mroz data supplied with the car package: > > require(car) > data(Mroz) > > there is no variable called "w" in that dataframe, but calling > > summary(Mroz$w) #### Mroz$w does not exist > > does not return any error but instead gives the same result as > > summary(Mroz$wc) ##### exists in Mroz > > > I find this behaviour *very* undesirable. Is there any way to switch > it off?It has always been the case. See the ?Extract page. The controlling sentence is here> " x$name is equivalent to x[["name", exact = FALSE]]. Also, the partial matching behavior of[[ can be controlled using the exact argument." (I'm using R2.14.2 ... further evidence this is not new in 2.15.x) > summary(Mroz$w) no yes 541 212 -- David Winsemius, MD West Hartford, CT
Whoops! Thanks to everyone and sorry for asking something so trivial and obvious for everyone. I really hadn't noticed it before. Cheers! i.> > ----- Original Message ----- > > From: David Winsemius > > Sent: 07/06/12 05:32 PM > > To: knallgrau at gmx.com > > Subject: Re: [R] automatic completion of object names > > > > On Jul 6, 2012, at 9:36 AM, knallgrau at gmx.com wrote: > > > > > Hello there, > > > > > > I just upgraded to R 2.15 (from R 2.12) on a Windows XP machine and > > > noticed some puzzling behaviour (that in my opinion did not exist in > > > R 2.12). > > > > > > It is possible now to call objects without spelling out the full > > > object name. R now seems to use that (unique) object which shares > > > the same beginning of the called object, even though the originally > > > called object might not even exist. > > > > > > This is quite awkwardly described, but perhaps you know what I'm > > > talking about? > > > > > > Let's say I'm using the Mroz data supplied with the car package: > > > > > > require(car) > > > data(Mroz) > > > > > > there is no variable called "w" in that dataframe, but calling > > > > > > summary(Mroz$w) #### Mroz$w does not exist > > > > > > does not return any error but instead gives the same result as > > > > > > summary(Mroz$wc) ##### exists in Mroz > > > > > > > > > I find this behaviour *very* undesirable. Is there any way to switch > > > it off? > > > > It has always been the case. See the ?Extract page. The controlling > > sentence is here> > > > > " x$name is equivalent to x[["name", exact = FALSE]]. Also, the > > partial matching behavior of[[ can be controlled using the exact > > argument." > > > > (I'm using R2.14.2 ... further evidence this is not new in 2.15.x) > > > > ?> summary(Mroz$w) > > ?no yes > > 541 212 > > > > -- > > David Winsemius, MD > > West Hartford, CT