An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/r-sig-mac/attachments/20071121/533fa43b/attachment.pl
A shorthand for '<-'
15 messages · James R. Milks, John Chambers, Simon Urbanek +5 more
James,
On Nov 21, 2007, at 8:22 AM, James Milks wrote:
The '=' sign can be used in place of '<-'. That's the only shorthand I know for R.
That's not a shorthand. `=` and `<-` are semantically different in R. Alexy was asking presumably about shorthands that you press/type in the R Mac GUI which will result in `<-` being produced and those are <Alt><-> (this comes from Emacs' "_" shortcut which you type on US keyboard as <Shift><-> but given that the character _ is often used these days, we created a variant where you use <Alt> instead of <Shift>) and <Ctrl><=> (this one is simply a play on the equal sign and should make sense on other keyboards, too). The last shorthand I mentioned (<Alt>+<=>) is a direct translation of the ? sign (which you get in other programs when pressing <Alt><=>) into R code. Cheers, Simon
An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/r-sig-mac/attachments/20071121/e30c1ff6/attachment.pl
I actually like = because I screw myself over with things like b[b<-1]=-1 on a regular basis. :-) Of course, I also manage to screw myself over with (b = 1 | x == 2) so perhaps there's simply no hope for me... Perhaps the Smalltalk-style assignment ':='....
On Nov 21, 2007 8:45 AM, John Chambers <jmc at r-project.org> wrote:
??? ? ???Simon Urbanek wrote:?James,?????On Nov 21, 2007, at 8:22 AM, James Milks wrote:??????> The '=' sign can be used in place of?'<-'. That's the only shorthand ?> I know for R.??> ??> ? ????That's not a shorthand. `=` and `<-` are semantically different in?R.????Well, not really :-)????It's true that the "=" operator won't be displayed as "<-", which ?I?agree was the original point. But both assignment operators map ?into?the same internal C code, if you dig into the implementation.????The "=" operator was added in S4 to assuage folks with C/Java/awk ?....?backgrounds who didn't care for the weird assignment operator. ?But?"real" S and R users still seem to like "<-" better.????Alexy was asking presumably about shorthands that you press/type in ?the?R Mac GUI which will result in `<-` being produced and those ?are?<Alt><-> (this comes from Emacs' "_" shortcut which you?type on US ?keyboard as <Shift><-> but given that the?character _ is often used ?these days, we c! reated a variant where you?use <Alt> instead of <Shift>) ?and <Ctrl><=>?(this one is simply a play on the equal sign and should ?make sense on?other keyboards, too). The last shorthand I ?mentioned?(<Alt>+<=>) is a direct translation of the ? sign (which?you ?get in other programs when pressing <Alt><=>) into R?code.?????Cheers,???Simon?????????------------------------------------------------------------------------??_______________________________________________?R-SIG-Mac mailing list?R-SIG-Mac at stat.math.ethz.ch?https://stat.ethz.ch/mailman/listinfo/r-sig-mac? ??????? [[alternative HTML version deleted]]
_______________________________________________ R-SIG-Mac mailing list R-SIG-Mac at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-mac
Byron Ellis (byron.ellis at gmail.com) "Oook" -- The Librarian
On Nov 21, 2007, at 11:45 AM, John Chambers wrote:
Simon Urbanek wrote: James, On Nov 21, 2007, at 8:22 AM, James Milks wrote:
The '=' sign can be used in place of '<-'. That's the only shorthand I know for R.
That's not a shorthand. `=` and `<-` are semantically different in R. Well, not really :-) It's true that the "=" operator won't be displayed as "<-", which I agree was the original point. But both assignment operators map into the same internal C code, if you di g into the implementation.
I think we may be talking about different things here. > a=list(a=1,b=2) > ls() [1] "a" > a<-list(a<-1,b<-2) > ls() [1] "a" "b" So `<-` and `=` are *not* semantically equivalent (where `<-` and `=` represent symbols in the parse tree). And I suppose the misunderstanding comes from the interpretation of `=` and `<-`: I meant them as symbols (which is what I would expect since we're talking about writing R code) and you interpreted them as operators (which cold be expected given that I used backticks which was not wise ;)). You are right that `=` and `<-` are equivalent as operators: > `=`(a,list(`=`(a,1),`=`(b,2))) > ls() [1] "a" "b" I hope this makes things even more clear ;). Cheers, Simon
The "=" operator was added in S4 to assuage folks with C/Java/ awk .... backgrounds who didn't care for the weird assignment operator. But "real" S and R users still seem to like "<-" better. Alexy was asking presumably about shorthands that you press/type in the R Mac GUI which will result in `<-` being produced and those are <Alt><-> (this comes from Emacs' "_" shortcut which you type on US keyboard as <Shift><-> but given that the character _ is often used these days, we created a variant where you use <Alt> instead of <Shift>) and <Ctrl><=> (this one is simply a play on the equal sign and should make sense on other keyboards, too). The last shorthand I mentioned (<Alt>+<=>) is a direct translation of the ? sign (which you get in other programs when pressing <Alt><=>) into R code. Cheers, Simon
_______________________________________________ R-SIG-Mac mailing list R-SIG-Mac at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-mac
On Nov 21, 2007, at 1:11 PM, Byron Ellis wrote:
I actually like = because I screw myself over with things like b[b<-1]=-1 on a regular basis. :-) Of course, I also manage to screw myself over with (b = 1 | x == 2) so perhaps there's simply no hope for me... Perhaps the Smalltalk-style assignment ':='....
Wasn't that ALGOL, really? ;) I must agree that I like it as well (and surprisingly it's still compatible with R's syntax - just in case we don't have enough assignment operators already) - but then, I'm one of those poor kids who grew up on Pascal, so I don't count ;). [Still, I wouldn't go as far as to re-introduce begin/end :P] Cheers, Simon
On Nov 21, 2007 8:45 AM, John Chambers <jmc at r-project.org> wrote:
??? ? ???Simon Urbanek wrote:?James,?????On Nov 21, 2007, at 8:22 AM, James Milks wrote:??????> The '=' sign can be used in place of?'<-'. That's the only shorthand ?> I know for R.??> ??> ? ???? That's not a shorthand. `=` and `<-` are semantically different in? R.????Well, not really :-)????It's true that the "=" operator won't be displayed as "<-", which ?I?agree was the original point. But both assignment operators map ?into?the same internal C code, if you dig into the implementation.????The "=" operator was added in S4 to assuage folks with C/Java/awk ?....?backgrounds who didn't care for the weird assignment operator. ?But?"real" S and R users still seem to like "<-" better.????Alexy was asking presumably about shorthands that you press/type in ?the?R Mac GUI which will result in `<-` being produced and those ?are?<Alt><-> (this comes from Emacs' "_" shortcut which you?type on US ?keyboard as <Shift><-> but given that the?character _ is often used ?these days, we c! reated a variant where you?use <Alt> instead of <Shift>) ?and <Ctrl><=>?(this one is simply a play on the equal sign and should ? make sense on?other keyboards, too). The last shorthand I ? mentioned?(<Alt>+<=>) is a direct translation of the sign (which? you ?get in other programs when pressing <Alt><=>) into R?code.????? Cheers,??? Simon ?????????------------------------------------------------------------------------??_______________________________________________ ?R-SIG-Mac mailing list?R-SIG-Mac at stat.math.ethz.ch?https://stat.ethz.ch/mailman/listinfo/r-sig-mac? ??????? [[alternative HTML version deleted]]
_______________________________________________ R-SIG-Mac mailing list R-SIG-Mac at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-mac
-- Byron Ellis (byron.ellis at gmail.com) "Oook" -- The Librarian
On Nov 21, 2007, at 9:19 PM, Simon Urbanek wrote:
[...]
So `<-` and `=` are *not* semantically equivalent (where `<-` and `=` represent symbols in the parse tree).
Guys, thanks for extremely illuminating discussion! I always liked '<-' more than '=' and am staunchly typing it. And of course there's a -> form. This is beautifully asymmetric. Now I can type <- in Emacs with '_' (in ESS) and in R.app with ?-. (Now if only I find how to do it in TextMate!... :) Cheers, Alexy
On Nov 21, 2007 10:27 AM, Simon Urbanek <simon.urbanek at r-project.org> wrote:
On Nov 21, 2007, at 1:11 PM, Byron Ellis wrote:
I actually like = because I screw myself over with things like b[b<-1]=-1 on a regular basis. :-) Of course, I also manage to screw myself over with (b = 1 | x == 2) so perhaps there's simply no hope for me... Perhaps the Smalltalk-style assignment ':='....
Wasn't that ALGOL, really? ;) I must agree that I like it as well (and surprisingly it's still compatible with R's syntax - just in case we don't have enough assignment operators already) - but then, I'm one of those poor kids who grew up on Pascal, so I don't count ;). [Still, I wouldn't go as far as to re-introduce begin/end :P]
I always thought it was a common mapping for the 3270's left arrow key (I also always assumed that's where S' <- operator came from) when PC-style keyboards started dominating, the same as the ^ operator in Smalltalk is a mapping to the up arrow key on the original keyboard. I too grew up on Pascal (Turbo Pascal 3. Imagine my disappointment in Anders Hejlsberg and C#, though it's now finally starting to Suck Less).
Cheers, Simon
On Nov 21, 2007 8:45 AM, John Chambers <jmc at r-project.org> wrote:
??? ? ???Simon Urbanek wrote:?James,?????On Nov 21, 2007, at 8:22 AM, James Milks wrote:??????> The '=' sign can be used in place of?'<-'. That's the only shorthand ?> I know for R.??> ??> ? ???? That's not a shorthand. `=` and `<-` are semantically different in? R.????Well, not really :-)????It's true that the "=" operator won't be displayed as "<-", which ?I?agree was the original point. But both assignment operators map ?into?the same internal C code, if you dig into the implementation.????The "=" operator was added in S4 to assuage folks with C/Java/awk ?....?backgrounds who didn't care for the weird assignment operator. ?But?"real" S and R users still seem to like "<-" better.????Alexy was asking presumably about shorthands that you press/type in ?the?R Mac GUI which will result in `<-` being produced and those ?are?<Alt><-> (this comes from Emacs' "_" shortcut which you?type on US ?keyboard as <Shift><-> but given that the?character _ is often used ?these days, we c! reated a variant where you?use <Alt> instead of <Shift>) ?and <Ctrl><=>?(this one is simply a play on the equal sign and should ? make sense on?other keyboards, too). The last shorthand I ? mentioned?(<Alt>+<=>) is a direct translation of the sign (which? you ?get in other programs when pressing <Alt><=>) into R?code.????? Cheers,??? Simon ?????????------------------------------------------------------------------------??_______________________________________________ ?R-SIG-Mac mailing list?R-SIG-Mac at stat.math.ethz.ch?https://stat.ethz.ch/mailman/listinfo/r-sig-mac? ??????? [[alternative HTML version deleted]]
_______________________________________________ R-SIG-Mac mailing list R-SIG-Mac at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-mac
-- Byron Ellis (byron.ellis at gmail.com) "Oook" -- The Librarian
Byron Ellis (byron.ellis at gmail.com) "Oook" -- The Librarian
Oh, just check out the TextMate R bundle, it's in there.
On Nov 21, 2007 10:32 AM, Alexy Khrabrov <deliverable at gmail.com> wrote:
On Nov 21, 2007, at 9:19 PM, Simon Urbanek wrote: [...]
So `<-` and `=` are *not* semantically equivalent (where `<-` and `=` represent symbols in the parse tree).
Guys, thanks for extremely illuminating discussion! I always liked '<-' more than '=' and am staunchly typing it. And of course there's a -> form. This is beautifully asymmetric. Now I can type <- in Emacs with '_' (in ESS) and in R.app with ?-. (Now if only I find how to do it in TextMate!... :) Cheers, Alexy
_______________________________________________ R-SIG-Mac mailing list R-SIG-Mac at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-mac
Byron Ellis (byron.ellis at gmail.com) "Oook" -- The Librarian
On Nov 21, 2007, at 9:36 PM, Byron Ellis wrote:
Oh, just check out the TextMate R bundle, it's in there.
I have it, and it talks to R.app beautifully -- but didn't find <- there. So wrote a snippet! Yay! Cheers, Alexy
On 11/21/2007 1:19 PM, Simon Urbanek wrote:
On Nov 21, 2007, at 11:45 AM, John Chambers wrote:
Simon Urbanek wrote: James, On Nov 21, 2007, at 8:22 AM, James Milks wrote:
The '=' sign can be used in place of '<-'. That's the only shorthand I know for R.
That's not a shorthand. `=` and `<-` are semantically different in R. Well, not really :-) It's true that the "=" operator won't be displayed as "<-", which I agree was the original point. But both assignment operators map into the same internal C code, if you di g into the implementation.
I think we may be talking about different things here.
> a=list(a=1,b=2) > ls()
[1] "a"
> a<-list(a<-1,b<-2) > ls()
[1] "a" "b" So `<-` and `=` are *not* semantically equivalent (where `<-` and `=` represent symbols in the parse tree). And I suppose the misunderstanding comes from the interpretation of `=` and `<-`: I meant them as symbols (which is what I would expect since we're talking about writing R code) and you interpreted them as operators (which cold be expected given that I used backticks which was not wise ;)). You are right that `=` and `<-` are equivalent as operators:
> `=`(a,list(`=`(a,1),`=`(b,2))) > ls()
[1] "a" "b" I hope this makes things even more clear ;).
Of course, even using them as operators the parser doesn't think they
are identical:
> if (a <- 1) cat("yes\n")
yes
> if (a = 1) cat("yes\n")
Error: unexpected '=' in "if (a ="
> if (`=`(a,1)) cat("yes\n")
yes
Duncan Murdoch
Duncan Murdoch wrote:
On 11/21/2007 1:19 PM, Simon Urbanek wrote:
On Nov 21, 2007, at 11:45 AM, John Chambers wrote:
Simon Urbanek wrote: James, On Nov 21, 2007, at 8:22 AM, James Milks wrote:
The '=' sign can be used in place of '<-'. That's the only shorthand I know for R.
That's not a shorthand. `=` and `<-` are semantically different in R. Well, not really :-) It's true that the "=" operator won't be displayed as "<-", which I agree was the original point. But both assignment operators map into the same internal C code, if you di g into the implementation.
I think we may be talking about different things here.
> a=list(a=1,b=2) > ls()
[1] "a"
> a<-list(a<-1,b<-2) > ls()
[1] "a" "b" So `<-` and `=` are *not* semantically equivalent (where `<-` and `=` represent symbols in the parse tree).
Ouch! That's a good example of why people complained when "=" was added as an operator. In your first expression, "=" is being used in two quite different ways. (You can make out a case that argument specification is a little like assignment, since it creates an object of that name in the environment of the call, but that's pretty subtle.) In a sense "=" inside a function call is not semantically an operator at all; it's absorbed by the parser into the internal structure that represents the call. In contrast, putting an assignment operator inside an argument to a function is very different (and, IMO, something to be avoided in writing clear S-language code.) The difference can be highlighted by looking at the parsed but unevaluated expressions in the two cases: > e1 = quote(list(a=1,b=2)) > e1[[2]] [1] 1 > names(e1) [1] "" "a" "b" > e2 = quote(list(a<-1, b<-2)) > e2[[2]] a <- 1 The "=" has in a sense disappeared, only affecting the names attribute of the language object.
And I suppose the misunderstanding comes from the interpretation of `=` and `<-`: I meant them as symbols (which is what I would expect since we're talking about writing R code) and you interpreted them as operators (which cold be expected given that I used backticks which was not wise ;)). You are right that `=` and `<-` are equivalent as operators:
> `=`(a,list(`=`(a,1),`=`(b,2))) > ls()
[1] "a" "b" I hope this makes things even more clear ;).
Of course, even using them as operators the parser doesn't think they are identical:
if (a <- 1) cat("yes\n")
yes
if (a = 1) cat("yes\n")
Error: unexpected '=' in "if (a ="
if (`=`(a,1)) cat("yes\n")
yes
Again, the parser prohibition comes from catching a classic programming
error in C (and another complaint about using "=" as an assignment
operator).
while(flag = 0) { // of course, I meant (flag == 0)
...
if(something(...)) flag = 1;
}
after which the programmer wonders why the loop never exits.
(These points recall some surprisingly religious arguments 10 years or
so ago ;-))
Duncan Murdoch
An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/r-sig-mac/attachments/20071121/1ca242ef/attachment.pl
Hi,
John Chambers wrote:
[...]
In a sense "=" inside a function call is not semantically an operator at all; it's absorbed by the parser into the internal structure that represents the call. In contrast, putting an assignment operator inside an argument to a function is very different (and, IMO, something to be avoided in writing clear S-language code.)
Not only in S or R. I would say this should be avoided in any language where the order in which the function args are evaluated is undetermined, especially in situations like this one: b <- 0 f(a <- b + 1, b <- 7) # will call f(1, 7) or f(8, 7)? [...]
Again, the parser prohibition comes from catching a classic programming
error in C (and another complaint about using "=" as an assignment
operator).
while(flag = 0) { // of course, I meant (flag == 0)
...
if(something(...)) flag = 1;
}
after which the programmer wonders why the loop never exits.
You mean, the loop will never enter. Cheers, H.
3 days later
Hi List,
Since upgrading to Leopard, the font (or just style?) of my plot
titles has changed. They used to be bold but are no longer. I tried to
force it using:
plot(1,1, main=expression(bold("title")))
... but there's no difference to
plot(1,1, main="title")
Am I missing a font or has something else changed? I need the old look
since I'm in the middle of a long document and I'd like consistency
with the plots I've made up to now.
Cheers,
Demitri