Arguments of 'transform'

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Arguments of 'transform'

Bill.Venables
If you would like a 10 second R puzzle, you might like to think about
this one:


> g <- expand.grid(long = 130:140, lat = -(10:25))
> gp <- transform(g, x = long, y = lat)
Error in transform(g, x = long, y = lat) :
        object "long" not found


I don't expect this hasn't come up before, but I can't find mention of
it.  I suggest that to minimise this little stumbling block for
beginners (and others) we either

        change the name of the principal argument in transform from 'x'
to, say '.x' (or even 'data' as it is in 'with' for example)  OR

        at least put a note in the help file for 'transform' in the
'Detalis' section to say
     
        *** NOTE: The only tag name unavailable to be used is 'x'. ***

Just another little seed.

Bill.

Bill Venables,
CMIS, CSIRO Laboratories,
PO Box 120, Cleveland, Qld. 4163
AUSTRALIA
Office Phone (email preferred): +61 7 3826 7251
Fax (if absolutely necessary):    +61 7 3826 7304
Mobile (rarely used):                +61 4 1963 4642
Home Phone:                          +61 7 3286 7700
mailto:[hidden email]
http://www.cmis.csiro.au/bill.venables/

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Arguments of 'transform'

Peter Dalgaard
<[hidden email]> writes:

> If you would like a 10 second R puzzle, you might like to think about
> this one:
>
>
> > g <- expand.grid(long = 130:140, lat = -(10:25))
> > gp <- transform(g, x = long, y = lat)
> Error in transform(g, x = long, y = lat) :
>         object "long" not found
>
>
> I don't expect this hasn't come up before, but I can't find mention of
> it.  I suggest that to minimise this little stumbling block for
> beginners (and others) we either
>
> change the name of the principal argument in transform from 'x'
> to, say '.x' (or even 'data' as it is in 'with' for example)  OR
>
> at least put a note in the help file for 'transform' in the
> 'Detalis' section to say
>      
> *** NOTE: The only tag name unavailable to be used is 'x'. ***

Yes it has come up before (surprisingly rarely though), and you're
probably right although changing argument names of functions should
never be taken lightly as there could be people using the current
ones.

>
> Just another little seed.

...which is connected to my grievances with attach() &c the other day.
Something about transform() just isn't The Right Way.

--
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - ([hidden email])                  FAX: (+45) 35327907

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Arguments of 'transform'

Fox, John
Dear Peter and Bill,

How about changing the current "x argument to something like "x."? That
should make the problem that Bill points out less likely and still be
backwards compatible with using "x" in the call to transform().

Regards,
 John

--------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox 
--------------------------------

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of Peter Dalgaard
> Sent: Saturday, February 11, 2006 4:43 AM
> To: [hidden email]
> Cc: [hidden email]; [hidden email]
> Subject: Re: [Rd] Arguments of 'transform'
>
> <[hidden email]> writes:
>
> > If you would like a 10 second R puzzle, you might like to
> think about
> > this one:
> >
> >
> > > g <- expand.grid(long = 130:140, lat = -(10:25)) gp <-
> transform(g,
> > > x = long, y = lat)
> > Error in transform(g, x = long, y = lat) :
> >         object "long" not found
> >
> >
> > I don't expect this hasn't come up before, but I can't find
> mention of
> > it.  I suggest that to minimise this little stumbling block for
> > beginners (and others) we either
> >
> > change the name of the principal argument in transform from 'x'
> > to, say '.x' (or even 'data' as it is in 'with' for example)  OR
> >
> > at least put a note in the help file for 'transform' in
> the 'Detalis'
> > section to say
> >      
> > *** NOTE: The only tag name unavailable to be used is 'x'. ***
>
> Yes it has come up before (surprisingly rarely though), and
> you're probably right although changing argument names of
> functions should never be taken lightly as there could be
> people using the current ones.
>
> >
> > Just another little seed.
>
> ...which is connected to my grievances with attach() &c the other day.
> Something about transform() just isn't The Right Way.
>
> --
>    O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
>   c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
>  (*) \(*) -- University of Copenhagen   Denmark          Ph:  
> (+45) 35327918
> ~~~~~~~~~~ - ([hidden email])                  FAX:
> (+45) 35327907
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Arguments of 'transform'

Bill.Venables
In reply to this post by Bill.Venables
Hi John,

Unfortunately I don't think that will fix it because of partial matching.

(That would be OK if the argument sequence were reversed to:

        function(..., x.)

since partial matching does not occur with arguments coming after ..., but it would break ALL existing code.)

Bill.

-----Original Message-----
From: John Fox [mailto:[hidden email]]
Sent: Sunday, 12 February 2006 1:39 AM
To: 'Peter Dalgaard'; Venables, Bill (CMIS, Cleveland)
Cc: [hidden email]
Subject: RE: [Rd] Arguments of 'transform'


Dear Peter and Bill,

How about changing the current "x argument to something like "x."? That
should make the problem that Bill points out less likely and still be
backwards compatible with using "x" in the call to transform().

Regards,
 John

--------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox 
--------------------------------

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of Peter Dalgaard
> Sent: Saturday, February 11, 2006 4:43 AM
> To: [hidden email]
> Cc: [hidden email]; [hidden email]
> Subject: Re: [Rd] Arguments of 'transform'
>
> <[hidden email]> writes:
>
> > If you would like a 10 second R puzzle, you might like to
> think about
> > this one:
> >
> >
> > > g <- expand.grid(long = 130:140, lat = -(10:25)) gp <-
> transform(g,
> > > x = long, y = lat)
> > Error in transform(g, x = long, y = lat) :
> >         object "long" not found
> >
> >
> > I don't expect this hasn't come up before, but I can't find
> mention of
> > it.  I suggest that to minimise this little stumbling block for
> > beginners (and others) we either
> >
> > change the name of the principal argument in transform from 'x'
> > to, say '.x' (or even 'data' as it is in 'with' for example)  OR
> >
> > at least put a note in the help file for 'transform' in
> the 'Detalis'
> > section to say
> >      
> > *** NOTE: The only tag name unavailable to be used is 'x'. ***
>
> Yes it has come up before (surprisingly rarely though), and
> you're probably right although changing argument names of
> functions should never be taken lightly as there could be
> people using the current ones.
>
> >
> > Just another little seed.
>
> ...which is connected to my grievances with attach() &c the other day.
> Something about transform() just isn't The Right Way.
>
> --
>    O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
>   c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
>  (*) \(*) -- University of Copenhagen   Denmark          Ph:  
> (+45) 35327918
> ~~~~~~~~~~ - ([hidden email])                  FAX:
> (+45) 35327907
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Arguments of 'transform'

Fox, John
Dear Bill,

I didn't realize that "x." would be partially matched by "x" when there was
a first (unnamed) argument in the function call -- but I see the error now.

Thanks,
 John

--------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox 
--------------------------------

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of
> [hidden email]
> Sent: Saturday, February 11, 2006 11:07 AM
> To: [hidden email]; [hidden email]
> Cc: [hidden email]
> Subject: Re: [Rd] Arguments of 'transform'
>
> Hi John,
>
> Unfortunately I don't think that will fix it because of
> partial matching.
>
> (That would be OK if the argument sequence were reversed to:
>
> function(..., x.)
>
> since partial matching does not occur with arguments coming
> after ..., but it would break ALL existing code.)
>
> Bill.
>
> -----Original Message-----
> From: John Fox [mailto:[hidden email]]
> Sent: Sunday, 12 February 2006 1:39 AM
> To: 'Peter Dalgaard'; Venables, Bill (CMIS, Cleveland)
> Cc: [hidden email]
> Subject: RE: [Rd] Arguments of 'transform'
>
>
> Dear Peter and Bill,
>
> How about changing the current "x argument to something like
> "x."? That
> should make the problem that Bill points out less likely and still be
> backwards compatible with using "x" in the call to transform().
>
> Regards,
>  John
>
> --------------------------------
> John Fox
> Department of Sociology
> McMaster University
> Hamilton, Ontario
> Canada L8S 4M4
> 905-525-9140x23604
> http://socserv.mcmaster.ca/jfox 
> --------------------------------
>
> > -----Original Message-----
> > From: [hidden email]
> > [mailto:[hidden email]] On Behalf Of Peter Dalgaard
> > Sent: Saturday, February 11, 2006 4:43 AM
> > To: [hidden email]
> > Cc: [hidden email]; [hidden email]
> > Subject: Re: [Rd] Arguments of 'transform'
> >
> > <[hidden email]> writes:
> >
> > > If you would like a 10 second R puzzle, you might like to
> > think about
> > > this one:
> > >
> > >
> > > > g <- expand.grid(long = 130:140, lat = -(10:25)) gp <-
> > transform(g,
> > > > x = long, y = lat)
> > > Error in transform(g, x = long, y = lat) :
> > >         object "long" not found
> > >
> > >
> > > I don't expect this hasn't come up before, but I can't find
> > mention of
> > > it.  I suggest that to minimise this little stumbling block for
> > > beginners (and others) we either
> > >
> > > change the name of the principal argument in transform from 'x'
> > > to, say '.x' (or even 'data' as it is in 'with' for example)  OR
> > >
> > > at least put a note in the help file for 'transform' in
> > the 'Detalis'
> > > section to say
> > >      
> > > *** NOTE: The only tag name unavailable to be used is 'x'. ***
> >
> > Yes it has come up before (surprisingly rarely though), and
> > you're probably right although changing argument names of
> > functions should never be taken lightly as there could be
> > people using the current ones.
> >
> > >
> > > Just another little seed.
> >
> > ...which is connected to my grievances with attach() &c the
> other day.
> > Something about transform() just isn't The Right Way.
> >
> > --
> >    O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
> >   c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
> >  (*) \(*) -- University of Copenhagen   Denmark          Ph:  
> > (+45) 35327918
> > ~~~~~~~~~~ - ([hidden email])                  FAX:
> > (+45) 35327907
> >
> > ______________________________________________
> > [hidden email] mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel