Charilaos Skiadas wrote:
And of course let's not forget that a particularly twisted individual
could overwrite =:
`=` - function(x,y) print(x+y)
3 = 4
[1] 7
3 - 4
Error in 3 - 4 : invalid (do_set) left-hand side to assignment
I also was for a while mystified by the -
Thank you (all) for the helpful explanations! My own R code tends to
simpler constructs, but now perhaps we can start having obfuscated
code competitions: something common in Perl, but I have not seen in R
(yet). Anyone up for the challenge?
Best wishes,
Mark
--
Dr. Mark Wardle
Specialist
Jonathan Baron [EMAIL PROTECTED] writes:
I think it is worth pointing out that, if you use ESS with (X)emacs,
- (with spaces) is produced when you type _. It requires only two
keystrokes (shift and -), and the spaces are done for you. The = sign
requires three because you need to type the
The answer in emacs is always Yes.
Type _ twice, and it will become an underscore. See
C-h k _
For the full help page.
-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Jeffrey J. Hallman
Is there a way to turn this off? I sometimes have to use variable
No.
f - function(a = 3, b = 4) a-b
f(b = 10)
[1] -7
f(b - 10)
[1] 6
but if you only replace it in the context:
x - ...
then it should be ok.
On Jan 13, 2008 5:41 PM, Nasser Abbasi [EMAIL PROTECTED] wrote:
hi;
When I first started looking at R code, I thought that the - notation for
Most R users believe that there is a clear distinction between - and
=.
Gabor's example is a wonderful illustration of that distinction.
Most users recommend - for assignment for greater clarity and
readability.
The important characteristic for readability is the space on both sides of
the
I think it is worth pointing out that, if you use ESS with (X)emacs,
- (with spaces) is produced when you type _. It requires only two
keystrokes (shift and -), and the spaces are done for you. The = sign
requires three because you need to type the spaces on each side.
Jon
.. and don't forget that 6 - x works but 6 = x won't ...
Gabor Grothendieck [EMAIL PROTECTED] 01/13/08 10:50 PM
No.
f - function(a = 3, b = 4) a-b
f(b = 10)
[1] -7
f(b - 10)
[1] 6
but if you only replace it in the context:
x - ...
then it should be ok.
On Jan 13, 2008 5:41 PM, Nasser
And of course let's not forget that a particularly twisted individual
could overwrite =:
`=` - function(x,y) print(x+y)
3 = 4
[1] 7
3 - 4
Error in 3 - 4 : invalid (do_set) left-hand side to assignment
I also was for a while mystified by the - assignment, and preferred
= instead, but
Quoth Mark Wardle on Prickle-Prickle, Chaos 14, 3174:
I can see that f(b - 10) is equivalent to f(assign(b), 10))
f(assign(b, 10))?
My undestanding is that assign applies to the parental environment;
but the return value of assign, namely 10, is passed to f as the local
variable a.
The default
On 14/01/2008, Gabor Grothendieck [EMAIL PROTECTED] wrote:
Its not related to scoping. f(b = 10) passes 10 as argument b
but f(b - 10) assigns to variable b (which has nothing to do with
argument b) and then passes the result of the b-10 expression (which is
10) to f. Since no argument was
On Mon, 14 Jan 2008, Mark Wardle wrote:
On 13/01/2008, Gabor Grothendieck [EMAIL PROTECTED] wrote:
No.
f - function(a = 3, b = 4) a-b
f(b = 10)
[1] -7
f(b - 10)
[1] 6
I had to go and read (and re-read) the R manual on lexical scope to
lexical scope does not come into this; S behaves
Its not related to scoping. f(b = 10) passes 10 as argument b
but f(b - 10) assigns to variable b (which has nothing to do with
argument b) and then passes the result of the b-10 expression (which is
10) to f. Since no argument was specified it uses positional
matching and the first position is
13 matches
Mail list logo