From: John Fox <jfox_at_mcmaster.ca>

Date: Thu, 31 Mar 2011 07:54:20 -0400

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. Received on Thu 31 Mar 2011 - 13:03:25 GMT

Date: Thu, 31 Mar 2011 07:54:20 -0400

Dear Ken and Bill,

Thanks for the comments. I obviously didn't think about the precedence issue and was unaware that one could define :=.

Best,

John

*> -----Original Message-----
**> From: Kenn Konstabel [mailto:lebatsnok_at_gmail.com]
**> Sent: March-31-11 7:12 AM
**> To: William Dunlap
**> Cc: John Fox; Carl Witthoft; r-help_at_r-project.org
**> Subject: Re: [R] how about a "<p-" operator?
**>
*

> In addition to %...% operators one can define := (I haven't seen this

*> possibility documented anywhere but it's used in a package) which seems to
**> have different precedence.
**>
**> > `:=`<-`%<-%` # the %<-% by John Fox
**> > a
**> [1] -1
**> > a := 1000 + 1
**> [1] 1001
**> > a
**> [1] 1001
**> > a %<-% 1000 + 1
**> [1] 1001
**> > a
**> [1] 1000
**>
**> Regards,
**> Kenn
**>
**> Kenn Konstabel
**> National Institute for Health Development Hiiu 42 Tallinn
**>
**> On Thu, Mar 31, 2011 at 2:50 AM, William Dunlap <wdunlap_at_tibco.com> wrote:
**> > The %...% operators are not a panacea.
**> > they have the same precedence as `*`
**> > and `/` (I think) so you get things like:
**> >
**> > > x %<-% 10 - 8 # %<-% has higher precedence than -
**> > [1] 2
**> > > x # not what you thought it would be
**> > [1] 10
**> >
**> > > x %<-% 10 ^3 # but lower than ^
**> > [1] 1000
**> > > x # this is what you expected
**> > [1] 1000
**> >
**> > It isn't that hard to write a package with your own parser in it.
**> > Just have it generate the call tree from your input text and call
**> > eval() on it.
**> >
**> > Bill Dunlap
**> > Spotfire, TIBCO Software
**> > wdunlap tibco.com
**> >
**> >> -----Original Message-----
**> >> From: r-help-bounces_at_r-project.org
**> >> [mailto:r-help-bounces_at_r-project.org] On Behalf Of John Fox
**> >> Sent: Wednesday, March 30, 2011 4:34 PM
**> >> To: 'Carl Witthoft'
**> >> Cc: r-help_at_r-project.org
**> >> Subject: Re: [R] how about a "<p-" operator?
**> >>
**> >> Dear Carl,
**> >>
**> >> I think that the following does what you want:
**> >>
**> >> > `%<-%` <- function(e1, e2){
**> >> + e1 <- deparse(substitute(e1))
**> >> + env <- parent.frame()
**> >> + assign(e1, e2, envir=env)
**> >> + e2
**> >> + }
**> >>
**> >> > x %<-% 10
**> >> [1] 10
**> >>
**> >> > x
**> >> [1] 10
**> >>
**> >> But, as has been pointed out, it's probably easier just to
**> >> parenthesize the usual assignment command.
**> >>
**> >> Regards,
**> >> John
**> >>
**> >> --------------------------------
**> >> John Fox
**> >> Senator William McMaster
**> >> Professor of Social Statistics
**> >> Department of Sociology
**> >> McMaster University
**> >> Hamilton, Ontario, Canada
**> >> http://socserv.mcmaster.ca/jfox
**> >>
**> >>
**> >>
**> >>
**> >> > -----Original Message-----
**> >> > From: r-help-bounces_at_r-project.org
**> >> [mailto:r-help-bounces_at_r-project.org]
**> >> > On Behalf Of Carl Witthoft
**> >> > Sent: March-30-11 7:00 PM
**> >> > To: r-help_at_r-project.org
**> >> > Subject: [R] how about a "<p-" operator?
**> >> >
**> >> > I was cursing Matlab again today (what else is new) because
**> >> the default
**> >> > action for every Matlab command is to spew the result to
**> >> the console, and
**> >> > one must remember to put that darn ";" at the end of every line.
**> >> >
**> >> > So I just wondered: was there ever a discussion as to
**> >> providing some
**> >> > modified version of the "<-" and "->" operators in R to do
**> >> the reverse?
**> >> > That is, since R does not print the values of a command
**> >> to the console,
**> >> > what if there were an operator such that
**> >> >
**> >> >
**> >> > newobject <p- somefunction()
**> >> >
**> >> > would do the same as
**> >> >
**> >> > print(newobject <- somefunction())
**> >> >
**> >> >
**> >> > Any thoughts?
**> >> > Carl
**> >> >
**> >> > ______________________________________________
**> >> > 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.
**> >>
**> >> ______________________________________________
**> >> 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.
**> >>
**> >
**> > ______________________________________________
**> > 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.
**> >
*

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. Received on Thu 31 Mar 2011 - 13:03:25 GMT

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.2.0, at Thu 31 Mar 2011 - 13:10:27 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*