Re: [R] Where are usages like == 2L documented?

2009-11-17 Thread Duncan Murdoch
I think your suggestions below indicate a difference in documentation 
philosophy between us.  I believe that things should be documented well 
in one place, and it should be easy to find that one place; you seem to 
be suggesting spreading out bits and pieces of documentation to many places.


The disadvantage of the many-place style is that it is hard to look up 
details.  I may remember seeing somewhere various rules about something, 
but if it isn't clear where to look for it again, I will have trouble 
finding it.


The weakness of the one-place style is that it isn't always easy to find 
that one place.  R documentation especially suffers from this, because 
it is hard to find things in the manuals if you're looking in the help() 
system.  I think the solution is to make it easier to find things in the 
manuals, rather than repeating bits and pieces of the manuals all across 
the help system.


One way to do this is to link the manuals into the help system, and I 
did some work on this last year, but unfortunately this requires a newer 
version of Texinfo than we are allowed to use because of FSF license 
restrictions.


Duncan Murdoch



On 16/11/2009 9:09 PM, Steven McKinney wrote:

-Original Message-
From: Gabor Grothendieck [mailto:ggrothendi...@gmail.com]
Sent: Monday, November 16, 2009 4:52 PM
To: Duncan Murdoch
Cc: Steven McKinney; R Help
Subject: Re: [R] Where are usages like == 2L documented?

On Mon, Nov 16, 2009 at 7:25 PM, Duncan Murdoch murd...@stats.uwo.ca
wrote:

On 16/11/2009 6:47 PM, Steven McKinney wrote:

?NumericConstants

will bring up a help page that mentions
All other numeric constants start with a digit or period and are

either a

decimal or hexadecimal constant optionally followed by L.

and

An numeric constant immediately followed by L is regarded as an

integer

number when possible (and with a warning if it contains a .). 


The word integer in the above sentence of the NumericConstants help
page is hyperlinked to the integer() function page.  There is then no
example or discussion of L there.


but I haven't found discussion of it anywhere else in the help

pages.

Others may know what other help pages discuss this.

I'm surprised that the help page invoked from
?integer
does not discuss this.  Anyone know why not?

This is part of the syntax of the language.  It has nothing to do

with the

integer() function, which is what ?integer is asking about.

It might be useful to have a SeeAlso to NumericConstants on that help
page for those who looked up ?integer thinking it might be about
integer constants.


Yes, additional discussion of L would be very valuable.  I've had
several people ask me about usages, as this original poster did.
I think that increased use of L has outpaced updating of help entries.
Given that L is appearing in more places, I'd like to request additional
discussion of it and examples using it in help pages.


class(1L)

[1] integer

storage.mode(1L)

[1] integer

Since integer is the term often associated with this language construct,
that seems a natural place to say something about it, and direct users
to other appropriate help pages.

The help page for storage.mode() shows an example with 1i in it,
could 1L please also be added?  (1.0 or 1. would also be useful.)

cex3 - c(NULL,1,1:1,1i,list(1),data.frame(x=1),
  pairlist(pi), c, lm, formals(lm)[[1]],  formals(lm)[[2]],
  y~x,expression((1))[[1]], (y~x)[[1]],
  expression(x - pi)[[1]][[1]])


The L language construct is often used in length checks such as
in the sample() function  if (length(x) == 1L ...

The length() function help page discusses
 The default method currently returns an integer of length 1.
again with the integer hyperlinked to the integer() help page.
Since length() therefore can only assess integer lengths
from 0 to about 2^31 - 1 it would be helpful to discuss this
integer L construct and the range of values that can be expressed
with mode integer more fully somewhere in one of these help topics.



sample
function (x, size, replace = FALSE, prob = NULL) 
{

if (length(x) == 1L  is.numeric(x)  x = 1) {
if (missing(size)) 
size - x

.Internal(sample(x, size, replace, prob))
}
else {
if (missing(size)) 
size - length(x)

x[.Internal(sample(length(x), size, replace, prob))]
}
}
environment: namespace:base


Best
Steve McKinney

__
R-help@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@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.


Re: [R] Where are usages like == 2L documented?

2009-11-17 Thread Bryan Hanson
Patrick reminded me that it's also in The R Inferno, another document that I
need to read again.

So now, a more particular semi-question:

x - 1L
y - 1
z - 1.0

class(x) # integer
class(y) # numeric
class(z) # numeric

x == 1
x == 1L
y == 1
z == 1 # all test TRUE

Just to clarify, I think the steps above prove it, but *in a test* like x ==
1 the test is for the contents, not the storage mode, not for a combination
of storage mode and contents.

So... The reason for defining the notion of L is smaller storage space,
and more generally, for use anytime one wants explictly an integer for
whatever reason?  Are there other reasons, for instance, ways it saves lines
of code?

Bryan
*
Bryan Hanson
Acting Chair
Professor of Chemistry  Biochemistry
DePauw University, Greencastle IN USA



On 11/17/09 4:20 AM, Patrick Burns pbu...@pburns.seanet.com wrote:

 'The R Inferno' page 75.
 
 
 
 Patrick Burns
 patr...@burns-stat.com
 +44 (0)20 8525 0696
 http://www.burns-stat.com
 (home of The R Inferno and A Guide for the Unwilling S User)
 
 Bryan Hanson wrote:
 Gurus:
 
 I keep seeing other people¹s code that contain ideas like
 
 If (x == 2L)
 X[-1L]
 X - 1L
 
 I have some idea of what¹s going on, but where is the use of concepts like
 ³2L² documented?
 
 Thanks, Bryan
 *
 Bryan Hanson
 Acting Chair
 Professor of Chemistry  Biochemistry
 DePauw University, Greencastle IN USA
 
 __
 R-help@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@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.


Re: [R] Where are usages like == 2L documented?

2009-11-17 Thread Prof Brian Ripley

On Tue, 17 Nov 2009, Bryan Hanson wrote:


Patrick reminded me that it's also in The R Inferno, another document that I
need to read again.

So now, a more particular semi-question:

x - 1L
y - 1
z - 1.0

class(x) # integer
class(y) # numeric
class(z) # numeric


NB: identical(x, y) is TRUE, so they behave the same.


x == 1
x == 1L
y == 1
z == 1 # all test TRUE

Just to clarify, I think the steps above prove it, but *in a test* like x ==
1 the test is for the contents, not the storage mode, not for a combination
of storage mode and contents.


Not really: the operands are coerced to a common type and then tested 
for equality.  From the help page for ==


 If the two arguments are atomic vectors of different types, one is
 coerced to the type of the other, the (decreasing) order of
 precedence being character, complex, numeric, integer, logical and
 raw.


So... The reason for defining the notion of L is smaller storage space,
and more generally, for use anytime one wants explictly an integer for
whatever reason?  Are there other reasons, for instance, ways it saves lines
of code?


It avoids coercion.  The test x == 1 requires x to be coerced from 
integer to double, and foo[1] requires '1' to be coerced from double 
to integer.  There is little if any gain in storage space for small 
integer vectors over small double vectors, but all those coercions can 
create a lot of new objects which need to be garbage-collected.


Also, 2L is simpler to write and to read than as.integer(2) (and 
avoids a funtion call and a coercion).




Bryan
*
Bryan Hanson
Acting Chair
Professor of Chemistry  Biochemistry
DePauw University, Greencastle IN USA



On 11/17/09 4:20 AM, Patrick Burns pbu...@pburns.seanet.com wrote:


'The R Inferno' page 75.



Patrick Burns
patr...@burns-stat.com
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of The R Inferno and A Guide for the Unwilling S User)

Bryan Hanson wrote:

Gurus:

I keep seeing other people¹s code that contain ideas like

If (x == 2L)
X[-1L]
X - 1L

I have some idea of what¹s going on, but where is the use of concepts like
³2L² documented?

Thanks, Bryan
*
Bryan Hanson
Acting Chair
Professor of Chemistry  Biochemistry
DePauw University, Greencastle IN USA

__
R-help@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@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.



--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595__
R-help@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.


Re: [R] Where are usages like == 2L documented?

2009-11-17 Thread Duncan Murdoch

On 16/11/2009 7:52 PM, Gabor Grothendieck wrote:

On Mon, Nov 16, 2009 at 7:25 PM, Duncan Murdoch murd...@stats.uwo.ca wrote:

On 16/11/2009 6:47 PM, Steven McKinney wrote:

?NumericConstants

will bring up a help page that mentions
All other numeric constants start with a digit or period and are either a
decimal or hexadecimal constant optionally followed by L.

and

An numeric constant immediately followed by L is regarded as an integer
number when possible (and with a warning if it contains a .). 

but I haven't found discussion of it anywhere else in the help pages.
Others may know what other help pages discuss this.

I'm surprised that the help page invoked from
?integer
does not discuss this.  Anyone know why not?

This is part of the syntax of the language.  It has nothing to do with the
integer() function, which is what ?integer is asking about.


It might be useful to have a SeeAlso to NumericConstants on that help
page for those who looked up ?integer thinking it might be about
integer constants.


I've added 1L, 1i and 0x1 as aliases for NumericConstants instead.

Duncan Murdoch

__
R-help@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.


Re: [R] Where are usages like == 2L documented?

2009-11-16 Thread David Winsemius


On Nov 16, 2009, at 6:22 PM, Bryan Hanson wrote:


Gurus:

I keep seeing other people’s code that contain ideas like

If (x == 2L)
X[-1L]
X - 1L

I have some idea of what’s going on, but where is the use of  
concepts like

“2L” documented?


Not sure where exactly, and it would depend on where you learned R.  
The integer data type information and notation should have been found  
among the material where you learned about numeric, character,  
logical,  that sort of basic notion.


--

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
R-help@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.


Re: [R] Where are usages like == 2L documented?

2009-11-16 Thread Duncan Murdoch

Bryan Hanson wrote:

Gurus:

I keep seeing other people¹s code that contain ideas like

If (x == 2L)
X[-1L]
X - 1L

I have some idea of what¹s going on, but where is the use of concepts like
³2L² documented?
  


In the R Language Definition manual.  In this case, look in section 
3.1.1, Constants.


Duncan Murdoch


Thanks, Bryan
*
Bryan Hanson
Acting Chair
Professor of Chemistry  Biochemistry
DePauw University, Greencastle IN USA

__
R-help@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@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.


Re: [R] Where are usages like == 2L documented?

2009-11-16 Thread Steven McKinney


?NumericConstants

will bring up a help page that mentions 

All other numeric constants start with a digit or period and are either a 
decimal or hexadecimal constant optionally followed by L.

and

An numeric constant immediately followed by L is regarded as an integer number 
when possible (and with a warning if it contains a .). 

but I haven't found discussion of it anywhere else in the help pages.
Others may know what other help pages discuss this.

I'm surprised that the help page invoked from
?integer
does not discuss this.  Anyone know why not?

Best
Steve McKinney




 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org] On Behalf Of Bryan Hanson
 Sent: Monday, November 16, 2009 3:23 PM
 To: R Help
 Subject: [R] Where are usages like == 2L documented?
 
 Gurus:
 
 I keep seeing other people¹s code that contain ideas like
 
 If (x == 2L)
 X[-1L]
 X - 1L
 
 I have some idea of what¹s going on, but where is the use of concepts
 like
 ³2L² documented?
 
 Thanks, Bryan
 *
 Bryan Hanson
 Acting Chair
 Professor of Chemistry  Biochemistry
 DePauw University, Greencastle IN USA
 
 __
 R-help@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@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.


Re: [R] Where are usages like == 2L documented?

2009-11-16 Thread Duncan Murdoch

On 16/11/2009 6:47 PM, Steven McKinney wrote:


?NumericConstants

will bring up a help page that mentions 


All other numeric constants start with a digit or period and are either a decimal 
or hexadecimal constant optionally followed by L.

and

An numeric constant immediately followed by L is regarded as an integer number when possible 
(and with a warning if it contains a .). 

but I haven't found discussion of it anywhere else in the help pages.
Others may know what other help pages discuss this.

I'm surprised that the help page invoked from
?integer
does not discuss this.  Anyone know why not?


This is part of the syntax of the language.  It has nothing to do with 
the integer() function, which is what ?integer is asking about.


Duncan Murdoch



Best
Steve McKinney





-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
project.org] On Behalf Of Bryan Hanson
Sent: Monday, November 16, 2009 3:23 PM
To: R Help
Subject: [R] Where are usages like == 2L documented?

Gurus:

I keep seeing other people¹s code that contain ideas like

If (x == 2L)
X[-1L]
X - 1L

I have some idea of what¹s going on, but where is the use of concepts
like
³2L² documented?

Thanks, Bryan
*
Bryan Hanson
Acting Chair
Professor of Chemistry  Biochemistry
DePauw University, Greencastle IN USA

__
R-help@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@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@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.


Re: [R] Where are usages like == 2L documented?

2009-11-16 Thread Gabor Grothendieck
On Mon, Nov 16, 2009 at 7:25 PM, Duncan Murdoch murd...@stats.uwo.ca wrote:
 On 16/11/2009 6:47 PM, Steven McKinney wrote:

 ?NumericConstants

 will bring up a help page that mentions
 All other numeric constants start with a digit or period and are either a
 decimal or hexadecimal constant optionally followed by L.

 and

 An numeric constant immediately followed by L is regarded as an integer
 number when possible (and with a warning if it contains a .). 

 but I haven't found discussion of it anywhere else in the help pages.
 Others may know what other help pages discuss this.

 I'm surprised that the help page invoked from
 ?integer
 does not discuss this.  Anyone know why not?

 This is part of the syntax of the language.  It has nothing to do with the
 integer() function, which is what ?integer is asking about.

It might be useful to have a SeeAlso to NumericConstants on that help
page for those who looked up ?integer thinking it might be about
integer constants.

__
R-help@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.


Re: [R] Where are usages like == 2L documented?

2009-11-16 Thread Bryan Hanson
As the OP, I will say that I had deduced that it probably was a way of
specifying type integer, so I went to the ?integer page hoping for further
info.  I agree there should be some kind of short comment or see also at
that page.  I've been a self-taught user of R for about a year and a half,
and this is one of the better hidden pieces of information.  I had looked at
the R Lang document, and probably should again for some additional ideas,
but that was a long time ago.  I did an RSiteSearch(1L) but not
surprisingly this returns many uses of the feature, not the definition, at
least not in the first few pages.

Thanks for the tips.  Bryan
*
Bryan Hanson
Acting Chair
Professor of Chemistry  Biochemistry
DePauw University, Greencastle IN USA



On 11/16/09 7:52 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote:

 On Mon, Nov 16, 2009 at 7:25 PM, Duncan Murdoch murd...@stats.uwo.ca wrote:
 On 16/11/2009 6:47 PM, Steven McKinney wrote:
 
 ?NumericConstants
 
 will bring up a help page that mentions
 All other numeric constants start with a digit or period and are either a
 decimal or hexadecimal constant optionally followed by L.
 
 and
 
 An numeric constant immediately followed by L is regarded as an integer
 number when possible (and with a warning if it contains a .). 
 
 but I haven't found discussion of it anywhere else in the help pages.
 Others may know what other help pages discuss this.
 
 I'm surprised that the help page invoked from
 ?integer
 does not discuss this.  Anyone know why not?
 
 This is part of the syntax of the language.  It has nothing to do with the
 integer() function, which is what ?integer is asking about.
 
 It might be useful to have a SeeAlso to NumericConstants on that help
 page for those who looked up ?integer thinking it might be about
 integer constants.
 
 __
 R-help@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@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.


Re: [R] Where are usages like == 2L documented?

2009-11-16 Thread Steven McKinney

 -Original Message-
 From: Gabor Grothendieck [mailto:ggrothendi...@gmail.com]
 Sent: Monday, November 16, 2009 4:52 PM
 To: Duncan Murdoch
 Cc: Steven McKinney; R Help
 Subject: Re: [R] Where are usages like == 2L documented?
 
 On Mon, Nov 16, 2009 at 7:25 PM, Duncan Murdoch murd...@stats.uwo.ca
 wrote:
  On 16/11/2009 6:47 PM, Steven McKinney wrote:
 
  ?NumericConstants
 
  will bring up a help page that mentions
  All other numeric constants start with a digit or period and are
 either a
  decimal or hexadecimal constant optionally followed by L.
 
  and
 
  An numeric constant immediately followed by L is regarded as an
 integer
  number when possible (and with a warning if it contains a .). 

The word integer in the above sentence of the NumericConstants help
page is hyperlinked to the integer() function page.  There is then no
example or discussion of L there.

 
  but I haven't found discussion of it anywhere else in the help
 pages.
  Others may know what other help pages discuss this.
 
  I'm surprised that the help page invoked from
  ?integer
  does not discuss this.  Anyone know why not?
 
  This is part of the syntax of the language.  It has nothing to do
 with the
  integer() function, which is what ?integer is asking about.
 
 It might be useful to have a SeeAlso to NumericConstants on that help
 page for those who looked up ?integer thinking it might be about
 integer constants.

Yes, additional discussion of L would be very valuable.  I've had
several people ask me about usages, as this original poster did.
I think that increased use of L has outpaced updating of help entries.
Given that L is appearing in more places, I'd like to request additional
discussion of it and examples using it in help pages.

 class(1L)
[1] integer
 storage.mode(1L)
[1] integer

Since integer is the term often associated with this language construct,
that seems a natural place to say something about it, and direct users
to other appropriate help pages.

The help page for storage.mode() shows an example with 1i in it,
could 1L please also be added?  (1.0 or 1. would also be useful.)

cex3 - c(NULL,1,1:1,1i,list(1),data.frame(x=1),
  pairlist(pi), c, lm, formals(lm)[[1]],  formals(lm)[[2]],
  y~x,expression((1))[[1]], (y~x)[[1]],
  expression(x - pi)[[1]][[1]])


The L language construct is often used in length checks such as
in the sample() function  if (length(x) == 1L ...

The length() function help page discusses
 The default method currently returns an integer of length 1.
again with the integer hyperlinked to the integer() help page.
Since length() therefore can only assess integer lengths
from 0 to about 2^31 - 1 it would be helpful to discuss this
integer L construct and the range of values that can be expressed
with mode integer more fully somewhere in one of these help topics.


 sample
function (x, size, replace = FALSE, prob = NULL) 
{
if (length(x) == 1L  is.numeric(x)  x = 1) {
if (missing(size)) 
size - x
.Internal(sample(x, size, replace, prob))
}
else {
if (missing(size)) 
size - length(x)
x[.Internal(sample(length(x), size, replace, prob))]
}
}
environment: namespace:base


Best
Steve McKinney

__
R-help@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.