Re: [R] how about a "<p-" operator?

From: John Fox <jfox_at_mcmaster.ca>
Date: Wed, 30 Mar 2011 19:34:24 -0400

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. Received on Wed 30 Mar 2011 - 23:38:39 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 - 00:40:26 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.

list of date sections of archive