[R] how about a "<p-" operator?
John Fox
jfox at mcmaster.ca
Thu Mar 31 01:34:24 CEST 2011
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.
More information about the R-help
mailing list