

CONTENTS DELETED
The author has deleted this message.


On Tue, Dec 7, 2010 at 8:43 AM, madr < [hidden email]> wrote:
>
> many languages have shorthands for that operation like:
>
> variable += 1
> or
> ++variable
>
> is there something like that in R ?
You can do this:
> x < 3
> `+`(x) < 1
> x
[1] 4

Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1877GKXGROUP
email: ggrothendieck at gmail.com
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


Indeed!
x < x + 1
(and being generous with unnecessary spaces) uses 10 characters.
`+`(x)<1
(being mean with them) uses 9. The "mean" version of the first
uses only 6: x<x+1
However, I suppose there is merit in the spiritual exercise
of contemplating how `+`(x)<1 gets worked out!
Ted.
On 07Dec10 16:23:17, Ivan Calandra wrote:
> x+1 is not that complicated... Am I missing something here?
>
> Le 12/7/2010 16:55, Gabor Grothendieck a écrit :
>> On Tue, Dec 7, 2010 at 8:43 AM, madr< [hidden email]> wrote:
>>> many languages have shorthands for that operation like:
>>>
>>> variable += 1
>>> or
>>> ++variable
>>>
>>> is there something like that in R ?
>>
>> You can do this:
>>
>>> x< 3
>>> `+`(x)< 1
>>> x
>> [1] 4
> 
> Ivan CALANDRA

EMail: (Ted Harding) < [hidden email]>
Faxtoemail: +44 (0)870 094 0861
Date: 07Dec10 Time: 16:42:44
 XFMail 
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


Ted:
Inline below...
On Tue, Dec 7, 2010 at 8:42 AM, Ted Harding < [hidden email]> wrote:
> Indeed!
>
> x < x + 1
>
> (and being generous with unnecessary spaces) uses 10 characters.
>
> `+`(x)<1
>
> (being mean with them) uses 9. The "mean" version of the first
> uses only 6: x<x+1
>
> However, I suppose there is merit in the spiritual exercise
> of contemplating how `+`(x)<1 gets worked out!
AFAICS it doesn't.
> `+`(x)<1
Error in +x < 1 : could not find function "+<"
`+`(x,1) does:
> `+`(x,1)
[1] 4
 Bert
>
> Ted.
>
> On 07Dec10 16:23:17, Ivan Calandra wrote:
>> x+1 is not that complicated... Am I missing something here?
>>
>> Le 12/7/2010 16:55, Gabor Grothendieck a écrit :
>>> On Tue, Dec 7, 2010 at 8:43 AM, madr< [hidden email]> wrote:
>>>> many languages have shorthands for that operation like:
>>>>
>>>> variable += 1
>>>> or
>>>> ++variable
>>>>
>>>> is there something like that in R ?
>>>
>>> You can do this:
>>>
>>>> x< 3
>>>> `+`(x)< 1
>>>> x
>>> [1] 4
>> 
>> Ivan CALANDRA
>
> 
> EMail: (Ted Harding) < [hidden email]>
> Faxtoemail: +44 (0)870 094 0861
> Date: 07Dec10 Time: 16:42:44
>  XFMail 
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/rhelp> PLEASE do read the posting guide http://www.Rproject.org/postingguide.html> and provide commented, minimal, selfcontained, reproducible code.
>

Bert Gunter
Genentech Nonclinical Biostatistics
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


On Tue, Dec 7, 2010 at 12:25 PM, Bert Gunter < [hidden email]> wrote:
> Ted:
>
> Inline below...
>
> On Tue, Dec 7, 2010 at 8:42 AM, Ted Harding < [hidden email]> wrote:
>> Indeed!
>>
>> x < x + 1
>>
>> (and being generous with unnecessary spaces) uses 10 characters.
>>
>> `+`(x)<1
>>
>> (being mean with them) uses 9. The "mean" version of the first
>> uses only 6: x<x+1
>>
>> However, I suppose there is merit in the spiritual exercise
>> of contemplating how `+`(x)<1 gets worked out!
>
> AFAICS it doesn't.
>> `+`(x)<1
> Error in +x < 1 : could not find function "+<"
Sorry, my code was missing the first line:
> `+<` < `+`
>
> x < 3
> `+`(x) < 1
> x
[1] 4

Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1877GKXGROUP
email: ggrothendieck at gmail.com
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


On Dec 7, 2010, at 12:42 PM, Gabor Grothendieck wrote:
> On Tue, Dec 7, 2010 at 12:25 PM, Bert Gunter
> < [hidden email]> wrote:
>> Ted:
>>
>> Inline below...
>>
>> On Tue, Dec 7, 2010 at 8:42 AM, Ted Harding
>> < [hidden email]> wrote:
>>> Indeed!
>>>
>>> x < x + 1
>>>
>>> (and being generous with unnecessary spaces) uses 10 characters.
>>>
>>> `+`(x)<1
>>>
>>> (being mean with them) uses 9. The "mean" version of the first
>>> uses only 6: x<x+1
>>>
>>> However, I suppose there is merit in the spiritual exercise
>>> of contemplating how `+`(x)<1 gets worked out!
>>
>> AFAICS it doesn't.
>>> `+`(x)<1
>> Error in +x < 1 : could not find function "+<"
>
> Sorry, my code was missing the first line:
>
>> `+<` < `+`
>>
>> x < 3
>> `+`(x) < 1
>> x
> [1] 4
One can also attempt further creative violence to the language that
shows that is possible to construct unary operators like the C
prefix"+" that do not require shift9 <operand> shift0.
> `+`
function (e1, e2) .Primitive("+")
> `+` < `` # in a different universe perhaps
> 4 + 2
[1] 2
> `+` < function (e1, e2) .Primitive("+") # attempt to restore
> 4 + 2 # test
function (e1, e2) .Primitive("+") ## oops
> `+` < .Primitive("+")
> 4 + 2
[1] 6 # "works"
> `!` < function(x) x + 1 # hijacking a logical NOT definition
> !3
[1] 4 # so this is a redefinition of one of the two unary operators
# ( of which I am aware, I'm not an Rguru.)
> `!` < .Primitive("!") ## hoping to restore expected behavior
> !3
[1] FALSE # whew. That seemed dangerous but I appear to have survived.

David Winsemius, MD
West Hartford, CT
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


On Tue, Dec 7, 2010 at 1:12 PM, David Winsemius < [hidden email]> wrote:
>
> On Dec 7, 2010, at 12:42 PM, Gabor Grothendieck wrote:
>
>> On Tue, Dec 7, 2010 at 12:25 PM, Bert Gunter < [hidden email]>
>> wrote:
>>>
>>> Ted:
>>>
>>> Inline below...
>>>
>>> On Tue, Dec 7, 2010 at 8:42 AM, Ted Harding < [hidden email]>
>>> wrote:
>>>>
>>>> Indeed!
>>>>
>>>> x < x + 1
>>>>
>>>> (and being generous with unnecessary spaces) uses 10 characters.
>>>>
>>>> `+`(x)<1
>>>>
>>>> (being mean with them) uses 9. The "mean" version of the first
>>>> uses only 6: x<x+1
>>>>
>>>> However, I suppose there is merit in the spiritual exercise
>>>> of contemplating how `+`(x)<1 gets worked out!
>>>
>>> AFAICS it doesn't.
>>>>
>>>> `+`(x)<1
>>>
>>> Error in +x < 1 : could not find function "+<"
>>
>> Sorry, my code was missing the first line:
>>
>>> `+<` < `+`
>>>
>>> x < 3
>>> `+`(x) < 1
>>> x
>>
>> [1] 4
>
> One can also attempt further creative violence to the language that shows
> that is possible to construct unary operators like the C prefix"+" that do
> not require shift9 <operand> shift0.
>
>> `+`
> function (e1, e2) .Primitive("+")
>> `+` < `` # in a different universe perhaps
>> 4 + 2
> [1] 2
>> `+` < function (e1, e2) .Primitive("+") # attempt to restore
>> 4 + 2 # test
> function (e1, e2) .Primitive("+") ## oops
>> `+` < .Primitive("+")
>> 4 + 2
> [1] 6 # "works"
>> `!` < function(x) x + 1 # hijacking a logical NOT definition
>> !3
> [1] 4 # so this is a redefinition of one of the two unary operators
> # ( of which I am aware, I'm not an Rguru.)
>
>> `!` < .Primitive("!") ## hoping to restore expected behavior
>> !3
> [1] FALSE # whew. That seemed dangerous but I appear to have survived.
Unlike the above, +< is not predefined so its definition does not
overwrite existing definitions.

Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1877GKXGROUP
email: ggrothendieck at gmail.com
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


On 07/12/2010 12:42 PM, Gabor Grothendieck wrote:
> On Tue, Dec 7, 2010 at 12:25 PM, Bert Gunter< [hidden email]> wrote:
>> Ted:
>>
>> Inline below...
>>
>> On Tue, Dec 7, 2010 at 8:42 AM, Ted Harding< [hidden email]> wrote:
>>> Indeed!
>>>
>>> x< x + 1
>>>
>>> (and being generous with unnecessary spaces) uses 10 characters.
>>>
>>> `+`(x)<1
>>>
>>> (being mean with them) uses 9. The "mean" version of the first
>>> uses only 6: x<x+1
>>>
>>> However, I suppose there is merit in the spiritual exercise
>>> of contemplating how `+`(x)<1 gets worked out!
>>
>> AFAICS it doesn't.
>>> `+`(x)<1
>> Error in +x< 1 : could not find function "+<"
>
> Sorry, my code was missing the first line:
>
>> `+<`< `+`
>>
>> x< 3
>> `+`(x)< 1
>> x
> [1] 4
Note that there are at least two subtle differences between your code
and x += 1 or ++x:
First, the value of `+`(x)< 1 is 1, i.e.
print(`+`(x)< 1)
will give 1 regardless of x, unlike ++x.
Another difference is that `+`(x)< 1 is equivalent to x < x + 1, and
in R, that doesn't necessarily increment x: the x on the right hand
side might be a global variable, and the result of x + 1 will be
assigned to a new local variable. For example, the sequence
x < 3
f < function() `+`(x)< 1
f()
x
leaves x set to 3. (But it temporarily created a new variable called x
in the evaluation frame of f().)
I don't think the first difference is documented; I haven't checked the
source to know if it's intentional. (It generally makes sense that "foo
< bar" has value bar; the problem is that your "assignment" doesn't
follow the rule that it assigns bar to foo.)
The second one is a basic fact of life in R, and the source of a few
bugs: the only way around it that I can see would be to allow users to
declare things about variables (e.g. "x is a global variable, don't
create a local when I assign to it!").
Duncan Murdoch
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.

