Re: [R] The L Word

2011-02-24 Thread Tal Galili
Thank you all for the answers.

So if I may extend on the question -
When is it important to use 'Literal integer'?
Under what situations could not using it cause problems?
Is it a matter of efficiency or precision or both?

Thanks,
Tal




Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--




On Wed, Feb 23, 2011 at 6:15 PM, Tsjerk Wassenaar tsje...@gmail.com wrote:

 Hi Gene,

 It means 'Literal integer'.
 So 1L is a proper integer 1, and 0L is a proper integer 0.

 Hope it helps,

 Tsjerk

 On Wed, Feb 23, 2011 at 5:08 PM, Gene Leynes gleyne...@gmail.com wrote:
  I've been wondering what L means in the R computing context, and was
  wondering if someone could point me to a reference where I could read
 about
  it, or tell me what it's called so that I can search for it myself.  (L
 by
  itself is a little too general for a search term).
 
  I encounter it in strange places, most recently in the save
 documentation.
 
  save(..., list = character(0L),
   file = stop('file' must be specified),
   ascii = FALSE, version = NULL, envir = parent.frame(),
   compress = !ascii, compression_level,
   eval.promises = TRUE, precheck = TRUE)
 
 
  I remember that you can also find it when you step inside an apply
 function:
 
  sapply(1:10, function(x)browser())
  Called from: FUN(1:10[[1L]], ...)
 
 
  I apologize for being vague, it's just something that I would like to
  understand about the R language (the R word).
 
  Thank you!
 
  Gene
 
 [[alternative HTML version deleted]]
 
  __
  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.
 



 --
 Tsjerk A. Wassenaar, Ph.D.

 post-doctoral researcher
 Molecular Dynamics Group
 * Groningen Institute for Biomolecular Research and Biotechnology
 * Zernike Institute for Advanced Materials
 University of Groningen
 The Netherlands

 __
 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.


[[alternative HTML version deleted]]

__
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] The L Word

2011-02-24 Thread Prof Brian Ripley

On Thu, 24 Feb 2011, Tal Galili wrote:


Thank you all for the answers.

So if I may extend on the question -
When is it important to use 'Literal integer'?
Under what situations could not using it cause problems?
Is it a matter of efficiency or precision or both?


Efficiency: it avoids unnecessary type conversions.  For example

length(x)  1

has to coerce the lhs to double.  We have converted the base code to 
use integer constants because such small efficiency gains can add up.


Integer vectors can be stored more compactly than doubles, but that is 
not going to help for length 1:



object.size(1)

48 bytes

object.size(1L)

48 bytes

(32-bit system).



Thanks,
Tal




Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--




On Wed, Feb 23, 2011 at 6:15 PM, Tsjerk Wassenaar tsje...@gmail.com wrote:


Hi Gene,

It means 'Literal integer'.
So 1L is a proper integer 1, and 0L is a proper integer 0.

Hope it helps,

Tsjerk

On Wed, Feb 23, 2011 at 5:08 PM, Gene Leynes gleyne...@gmail.com wrote:

I've been wondering what L means in the R computing context, and was
wondering if someone could point me to a reference where I could read

about

it, or tell me what it's called so that I can search for it myself.  (L

by

itself is a little too general for a search term).

I encounter it in strange places, most recently in the save

documentation.


save(..., list = character(0L),

 file = stop('file' must be specified),
 ascii = FALSE, version = NULL, envir = parent.frame(),
 compress = !ascii, compression_level,
 eval.promises = TRUE, precheck = TRUE)



I remember that you can also find it when you step inside an apply

function:



sapply(1:10, function(x)browser())
Called from: FUN(1:10[[1L]], ...)



I apologize for being vague, it's just something that I would like to
understand about the R language (the R word).

Thank you!

Gene

   [[alternative HTML version deleted]]

__
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.





--
Tsjerk A. Wassenaar, Ph.D.

post-doctoral researcher
Molecular Dynamics Group
* Groningen Institute for Biomolecular Research and Biotechnology
* Zernike Institute for Advanced Materials
University of Groningen
The Netherlands

__
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.



[[alternative HTML version deleted]]

__
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] The L Word

2011-02-24 Thread Claudia Beleites

On 02/24/2011 11:20 AM, Prof Brian Ripley wrote:

On Thu, 24 Feb 2011, Tal Galili wrote:


Thank you all for the answers.

So if I may extend on the question -
When is it important to use 'Literal integer'?
Under what situations could not using it cause problems?
Is it a matter of efficiency or precision or both?


Efficiency: it avoids unnecessary type conversions. For example

length(x)  1

has to coerce the lhs to double. We have converted the base code to use integer
constants because such small efficiency gains can add up.

Integer vectors can be stored more compactly than doubles, but that is not going
to help for length 1:


object.size(1)

48 bytes

object.size(1L)

48 bytes
(32-bit system).

see:
n - 0L : 100L
szi - sapply (n, function (n) object.size (integer (n)))
szd - sapply (n, function (n) object.size (double (n)))
plot (n, szd)
points (n, szi, col = red)








Thanks,
Tal




Contact
Details:---
Contact me: tal.gal...@gmail.com | 972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--





On Wed, Feb 23, 2011 at 6:15 PM, Tsjerk Wassenaar tsje...@gmail.com wrote:


Hi Gene,

It means 'Literal integer'.
So 1L is a proper integer 1, and 0L is a proper integer 0.

Hope it helps,

Tsjerk

On Wed, Feb 23, 2011 at 5:08 PM, Gene Leynes gleyne...@gmail.com wrote:

I've been wondering what L means in the R computing context, and was
wondering if someone could point me to a reference where I could read

about

it, or tell me what it's called so that I can search for it myself. (L

by

itself is a little too general for a search term).

I encounter it in strange places, most recently in the save

documentation.


save(..., list = character(0L),

file = stop('file' must be specified),
ascii = FALSE, version = NULL, envir = parent.frame(),
compress = !ascii, compression_level,
eval.promises = TRUE, precheck = TRUE)



I remember that you can also find it when you step inside an apply

function:



sapply(1:10, function(x)browser())
Called from: FUN(1:10[[1L]], ...)



I apologize for being vague, it's just something that I would like to
understand about the R language (the R word).

Thank you!

Gene

[[alternative HTML version deleted]]

__
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.





--
Tsjerk A. Wassenaar, Ph.D.

post-doctoral researcher
Molecular Dynamics Group
* Groningen Institute for Biomolecular Research and Biotechnology
* Zernike Institute for Advanced Materials
University of Groningen
The Netherlands

__
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.



[[alternative HTML version deleted]]

__
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.






--
Claudia Beleites
Dipartimento dei Materiali e delle Risorse Naturali
Università degli Studi di Trieste
Via Alfonso Valerio 6/a
I-34127 Trieste

phone: +39 0 40 5 58-37 68
email: cbelei...@units.it

__
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] The L Word

2011-02-24 Thread Bryan Hanson
This came up at least once before, with regard to where it is  
documented:


http://r.789695.n4.nabble.com/Where-are-usages-like-quot-2L-quot-documented-tt831061.html

I haven't looked around much to see if the documentation has changed,  
but in a quick look at ?integer I don't see the concept mentioned.  Of  
course, it could be somewhere else.  But, the concept is pretty  
straightfoward.


Bryan

Prof. Bryan Hanson
Dept of Chemistry  Biochemistry
DePauw University
602 S. College Ave
Greencastle IN 46135 USA

On Feb 24, 2011, at 3:13 AM, Tal Galili wrote:


Thank you all for the answers.

So if I may extend on the question -
When is it important to use 'Literal integer'?
Under what situations could not using it cause problems?
Is it a matter of efficiency or precision or both?

Thanks,
Tal




Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il  
(Hebrew) |

www.r-statistics.com (English)
--




On Wed, Feb 23, 2011 at 6:15 PM, Tsjerk Wassenaar  
tsje...@gmail.com wrote:



Hi Gene,

It means 'Literal integer'.
So 1L is a proper integer 1, and 0L is a proper integer 0.

Hope it helps,

Tsjerk

On Wed, Feb 23, 2011 at 5:08 PM, Gene Leynes gleyne...@gmail.com  
wrote:

I've been wondering what L means in the R computing context, and was
wondering if someone could point me to a reference where I could  
read

about
it, or tell me what it's called so that I can search for it  
myself.  (L

by

itself is a little too general for a search term).

I encounter it in strange places, most recently in the save

documentation.


save(..., list = character(0L),

file = stop('file' must be specified),
ascii = FALSE, version = NULL, envir = parent.frame(),
compress = !ascii, compression_level,
eval.promises = TRUE, precheck = TRUE)



I remember that you can also find it when you step inside an apply

function:



sapply(1:10, function(x)browser())
Called from: FUN(1:10[[1L]], ...)



I apologize for being vague, it's just something that I would like  
to

understand about the R language (the R word).

Thank you!

Gene

  [[alternative HTML version deleted]]

__
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.





--
Tsjerk A. Wassenaar, Ph.D.

post-doctoral researcher
Molecular Dynamics Group
* Groningen Institute for Biomolecular Research and Biotechnology
* Zernike Institute for Advanced Materials
University of Groningen
The Netherlands

__
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.



[[alternative HTML version deleted]]

__
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] The L Word

2011-02-24 Thread Martin Maechler
 CB == Claudia Beleites cbelei...@units.it
 on Thu, 24 Feb 2011 12:31:55 +0100 writes:

CB On 02/24/2011 11:20 AM, Prof Brian Ripley wrote:
 On Thu, 24 Feb 2011, Tal Galili wrote:
 
 Thank you all for the answers.
 
 So if I may extend on the question -
 When is it important to use 'Literal integer'?
 Under what situations could not using it cause problems?
 Is it a matter of efficiency or precision or both?
 
 Efficiency: it avoids unnecessary type conversions. For example
 
 length(x)  1
 
 has to coerce the lhs to double. We have converted the base
 code to use integer constants because such small efficiency
 gains can add up.
 
 Integer vectors can be stored more compactly than doubles, but
 that is not going to help for length 1:
 
 object.size(1)
 48 bytes
 object.size(1L)
 48 bytes
 (32-bit system).
CB see:

CB n - 0L : 100L

CB szi - sapply (n, function (n) object.size (integer (n)))
CB szd - sapply (n, function (n) object.size (double (n)))
CB plot (n, szd)
CB points (n, szi, col = red)

yes. 

Note however that I've never seen evidence for a *practical*
difference in simple cases, and also of such cases as part of a
larger computation.
But I'm happy to see one if anyone has an interesting example.

E.g., I would typically never use  0L:100L  instead of 0:100
in an R script because I think code readability (and self
explainability) is of considerable importance too.

Martin

__
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] The L Word

2011-02-24 Thread Hadley Wickham
 Note however that I've never seen evidence for a *practical*
 difference in simple cases, and also of such cases as part of a
 larger computation.
 But I'm happy to see one if anyone has an interesting example.

 E.g., I would typically never use  0L:100L  instead of 0:100
 in an R script because I think code readability (and self
 explainability) is of considerable importance too.

But : casts to integer anyway:

 str(0:100)
 int [1:101] 0 1 2 3 4 5 6 7 8 9 ...

And performance in this case is (obviously) negligible:

 library(microbenchmark)
 microbenchmark(as.integer(c(0, 100)), times = 1000)
Unit: nanoeconds
  min  lq median  uq   max
as.integer(c(0, 100)) 712 791813 896 15840

(mainly included as opportunity to try out microbenchmark)

So you save ~800 ns but typing two letters probably takes 0.2 s (100
wpm, ~ 5 letters per word + space = 0.1s per letter), so it only saves
you time if you're going to be calling it more than 125000 times ;)

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

__
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] The L Word

2011-02-24 Thread Martin Maechler
 HW == Hadley Wickham had...@rice.edu
 on Thu, 24 Feb 2011 10:14:35 -0600 writes:

 Note however that I've never seen evidence for a *practical*
 difference in simple cases, and also of such cases as part of a
 larger computation.
 But I'm happy to see one if anyone has an interesting example.
 
 E.g., I would typically never use  0L:100L  instead of 0:100
 in an R script because I think code readability (and self
 explainability) is of considerable importance too.

HW But : casts to integer anyway:

 str(0:100)
HW int [1:101] 0 1 2 3 4 5 6 7 8 9 ...

Sure !!  I've been the one who had use  0:0  or 1:1  
in those rare cases integers where required (e.g. in .C(..)),
before the L word existed.

HW And performance in this case is (obviously) negligible:

 library(microbenchmark)
 microbenchmark(as.integer(c(0, 100)), times = 1000)
HW Unit: nanoeconds
HW min  lq median  uq   max
HW as.integer(c(0, 100)) 712 791813 896 15840

HW (mainly included as opportunity to try out microbenchmark)
??
Thanks!  Did not know it.

*HOWEVER*   the above   as.integer(c(0,100))
is of course *much more* than what is internally needed to cast
the two doubles to integer.

Try this a few times ... and wonder :

  boxplot(mb2 - microbenchmark(L = 1L:100L, 1:100, times=5000),  notch=TRUE)

   mb2
  Unit: nanoeconds
min  lq median  uq  max
  L 316 410472 555 6843
  1:100 311 393440 497 7309

the result (on my 64-bit linux) seems to indicate that  1L:100L 
takes even slightly (but significantly [notches]) longer.

However, using

   boxplot(mb - microbenchmark(1:100, L = 1L:100L, times=5000), notch=TRUE)

   mb
  Unit: nanoeconds
min  lq median  uq   max
  1:100 296 401469 550  9426
  L 313 396438 496 16525

is less conclusive.. 
so, actually this is exactly one of those cases 
I do *not* see a difference, even if I look very hard.

{ BTW: There's at least one (if not two) buglet in 'microbenchmark'
  which I evaded using L =  above :

 1) It should not use   as.character(exprs)  
but rather  unlist(lapply(exprs, deparse))

 2) boxplot.microbenchmark should probably be more careful for
 the case when two rows have the same name (as it happens if
 I leave away L =  above)
}

Martin

__
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] The L Word

2011-02-24 Thread Martin Maechler
 MM == Martin Maechler maech...@stat.math.ethz.ch
 on Thu, 24 Feb 2011 18:34:36 +0100 writes:

 HW == Hadley Wickham had...@rice.edu
 on Thu, 24 Feb 2011 10:14:35 -0600 writes:

 Note however that I've never seen evidence for a *practical*
 difference in simple cases, and also of such cases as part of
 a larger computation.  But I'm happy to see one if anyone has
 an interesting example.
 
 E.g., I would typically never use  0L:100L  instead of 0:100
 in an R script because I think code readability (and self
 explainability) is of considerable importance too.

HW But : casts to integer anyway:

 str(0:100)
HW int [1:101] 0 1 2 3 4 5 6 7 8 9 ...

MM Sure !!  I've been the one who had use  0:0  or 1:1  
MM in those rare cases integers where required (e.g. in .C(..)),
MM before the L word existed.

HW And performance in this case is (obviously) negligible:

 library(microbenchmark)
 microbenchmark(as.integer(c(0, 100)), times = 1000)
HW Unit: nanoeconds
HW min  lq median  uq   max
HW as.integer(c(0, 100)) 712 791813 896 15840

HW (mainly included as opportunity to try out microbenchmark)
MM ??
MM Thanks!  Did not know it.

MM *HOWEVER* the above as.integer(c(0,100)) is of course
MM *much more* than what is internally needed to cast 
MM the two   doubles to integer.

MM Try this a few times ... and wonder :

MM boxplot(mb2 - microbenchmark(L = 1L:100L, 1:100, times=5000), 
notch=TRUE

 mb2
MM Unit: nanoeconds
MM min  lq median  uq  max
MM L 316 410472 555 6843
MM 1:100 311 393440 497 7309

MM the result (on my 64-bit linux) seems to indicate that 1L:100L
MM takes even slightly (but significantly [notches]) longer.

MM However, using

MM boxplot(mb - microbenchmark(1:100, L = 1L:100L, times=5000),
notch=TRUE)

 mb
MM Unit: nanoeconds
MM min  lq median  uq   max
MM 1:100 296 401469 550  9426
MM L 313 396438 496 16525

MM is less conclusive.. 
MM so, actually this is exactly one of those cases 
MM I do *not* see a difference, even if I look very hard.

MM { BTW: There's at least one (if not two) buglet in
MM'microbenchmark'   which I evaded using L =  above :

MM 1) It should not use   as.character(exprs)  
MM but rather  unlist(lapply(exprs, deparse))

MM 2) boxplot.microbenchmark should probably be more careful for
MM the case when two rows have the same name (as it happens if
MM I leave away L =  above)
MM }

and I forgot the buglet in  print.microbenchmark which says
nanoeconds (missing s).

BTW: Another -- more realistic example where I can't see any
advantage of using L is  x[1L]  vs  x[1] :

   str(x - 0 + 1:100)
   num [1:100] 1 2 3 4 5 6 7 8 9 10 ...
   t. - microbenchmark(x[1], times=5000)
   tL - microbenchmark(x[1L], times=5000)
   t.
  Unit: nanoeconds
   min  lq median  uq  max
  x[1] 198 208  241.5 299 4843
   tL
  Unit: nanoeconds
   min  lq median  uq  max
  x[1] 194 208234 296 6304
   

so the noise is much much larger than a noticable difference.

Martin

__
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] The L Word

2011-02-24 Thread William Dunlap

 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of Martin Maechler
 Sent: Thursday, February 24, 2011 7:45 AM
 To: Claudia Beleites
 Cc: r-help@r-project.org
 Subject: Re: [R] The L Word
 
  CB == Claudia Beleites cbelei...@units.it
  on Thu, 24 Feb 2011 12:31:55 +0100 writes:
 
 CB On 02/24/2011 11:20 AM, Prof Brian Ripley wrote:
  On Thu, 24 Feb 2011, Tal Galili wrote:
  
  Thank you all for the answers.
  
  So if I may extend on the question -
  When is it important to use 'Literal integer'?
  Under what situations could not using it cause problems?
  Is it a matter of efficiency or precision or both?
  
  Efficiency: it avoids unnecessary type conversions. For example
  
  length(x)  1
  
  has to coerce the lhs to double. We have converted the base
  code to use integer constants because such small efficiency
  gains can add up.
  
  Integer vectors can be stored more compactly than doubles, but
  that is not going to help for length 1:
  
  object.size(1)
  48 bytes
  object.size(1L)
  48 bytes
  (32-bit system).
 CB see:
 
 CB n - 0L : 100L
 
 CB szi - sapply (n, function (n) object.size (integer (n)))
 CB szd - sapply (n, function (n) object.size (double (n)))
 CB plot (n, szd)
 CB points (n, szi, col = red)
 
 yes. 
 
 Note however that I've never seen evidence for a *practical*
 difference in simple cases, and also of such cases as part of a
 larger computation.
 But I'm happy to see one if anyone has an interesting example.

I don't know how interesting this example is, but I use digitsL
when combining a scalar with what I know is an integer vector so
I don't unnecessarily change its type.  Also, if I have a function
that returns an integer vector in general cases but a special value
like NA or -1 in unusual cases, I would use NA_integer_ or -1L for those
special cases so the function returns the same class of data in
all cases.  These things can be important when trying to write a
faster/better version of a builtin function, where I
want to make the new output exactly match the original.

E.g., here is a function that does exactly what sequence() does
but is about 10 times faster for long input vectors (say
seq_len(1e6)%%4L):
  Sequence.L - function (nvec) 
  {
  seq_len(sum(nvec)) - rep(cumsum(c(0L, nvec[-length(nvec)])), nvec)
  }
If I change the 0L to 0.0 (or 0) then its result is no longer identical
to sequence's result.

(If I were designing a new data analysis language from scratch, I'd
be tempted to omit the integer type and make all numbers 64-bit doubles,
logicals 1 byte or 2 bit things, and maybe throw in some integral
types for image processing but not for general use.  32-bit integers
are pretty limiting.)

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

 
 E.g., I would typically never use  0L:100L  instead of 0:100
 in an R script because I think code readability (and self
 explainability) is of considerable importance too.
 
 Martin
 
 __
 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] The L Word

2011-02-24 Thread Claudia Beleites

On 02/24/2011 05:14 PM, Hadley Wickham wrote:

Note however that I've never seen evidence for a *practical*
difference in simple cases, and also of such cases as part of a
larger computation.
But I'm happy to see one if anyone has an interesting example.

E.g., I would typically never use  0L:100L  instead of 0:100
in an R script because I think code readability (and self
explainability) is of considerable importance too.


But : casts to integer anyway:
I know - I just thought that on _this_ thread I ought to write it with L ;-) and 
I don't think I write 1L : 100L in real life.


I use the L far more often as a reminder than for performance. Particularly in 
function definitions.





str(0:100)

  int [1:101] 0 1 2 3 4 5 6 7 8 9 ...

And performance in this case is (obviously) negligible:


library(microbenchmark)
microbenchmark(as.integer(c(0, 100)), times = 1000)

Unit: nanoeconds
   min  lq median  uq   max
as.integer(c(0, 100)) 712 791813 896 15840

(mainly included as opportunity to try out microbenchmark)



So you save ~800 ns but typing two letters probably takes 0.2 s (100
wpm, ~ 5 letters per word + space = 0.1s per letter), so it only saves
you time if you're going to be calling it more than 125000 times ;)
calling 125000 times happens in my real life. I have e.g. one data set with 2e5 
spectra (and another batch of that size waiting for me), so anything done for 
each spectrum reaches this number each time the function is needed.

Also of course, the conversion time goes with the length of the vector.
On the other hand, in  95 % of the cases taking an hour to think about the 
algorithm will have much larger effects ;-).


Also, I notice that the first few measures of microbenchmark are often much 
longer (for fast operations). Which may just indicate that the total speed 
depends much more on whether the code allows caching or not. And that may mean 
that any such coding details may or may not help at all: A single such 
conversion may take disproportionally much more time.


I just (yesterday) came across a situation where the difference between numeric 
and integer does matter (considering that I do that with ≈ 3e4 x 125 x 6 array 
size): as.factor

 microbenchmark (i = as.factor (1:1e3), d = as.factor ((1:1e3)+0.0))
Unit: nanoeconds
   min  lq  median  uq max
i   884039  891106  895847  901630 2524877
d  2698637 2770936 2778271 2807572 4266197

but then:
 microbenchmark (
sd = structure ((1:1e3)+0.0, .Label = 1:100, class = factor),
si = structure ((1:1e3)+0L, .Label = 1:100, class = factor))
Unit: nanoeconds
   min  lq  median  uq max
sd   52875   53615   54040   54448 1385422
si   45904   46936   47332   47778   65360



Cheers,

Claudia



--
Claudia Beleites
Dipartimento dei Materiali e delle Risorse Naturali
Università degli Studi di Trieste
Via Alfonso Valerio 6/a
I-34127 Trieste

phone: +39 0 40 5 58-37 68
email: cbelei...@units.it

__
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] The L Word

2011-02-23 Thread Gene Leynes
I've been wondering what L means in the R computing context, and was
wondering if someone could point me to a reference where I could read about
it, or tell me what it's called so that I can search for it myself.  (L by
itself is a little too general for a search term).

I encounter it in strange places, most recently in the save documentation.

save(..., list = character(0L),
  file = stop('file' must be specified),
  ascii = FALSE, version = NULL, envir = parent.frame(),
  compress = !ascii, compression_level,
  eval.promises = TRUE, precheck = TRUE)


I remember that you can also find it when you step inside an apply function:

 sapply(1:10, function(x)browser())
 Called from: FUN(1:10[[1L]], ...)


I apologize for being vague, it's just something that I would like to
understand about the R language (the R word).

Thank you!

Gene

[[alternative HTML version deleted]]

__
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] The L Word

2011-02-23 Thread Erik Iverson

Gene, it's described in ?NumericConstants

HTH, Erik

Gene Leynes wrote:

I've been wondering what L means in the R computing context, and was
wondering if someone could point me to a reference where I could read about
it, or tell me what it's called so that I can search for it myself.  (L by
itself is a little too general for a search term).

I encounter it in strange places, most recently in the save documentation.

save(..., list = character(0L),

 file = stop('file' must be specified),
 ascii = FALSE, version = NULL, envir = parent.frame(),
 compress = !ascii, compression_level,
 eval.promises = TRUE, precheck = TRUE)



I remember that you can also find it when you step inside an apply function:


sapply(1:10, function(x)browser())
Called from: FUN(1:10[[1L]], ...)



I apologize for being vague, it's just something that I would like to
understand about the R language (the R word).

Thank you!

Gene

[[alternative HTML version deleted]]

__
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] The L Word

2011-02-23 Thread Claudia Beleites

On 02/23/2011 05:08 PM, Gene Leynes wrote:

I've been wondering what L means in the R computing context, and was
wondering if someone could point me to a reference where I could read about
it, or tell me what it's called so that I can search for it myself.  (L by
itself is a little too general for a search term).

It means that the number is an integer (a _L_ong integer of 32 bit actually)





I encounter it in strange places, most recently in the save documentation.

save(..., list = character(0L),

  file = stop('file' must be specified),
  ascii = FALSE, version = NULL, envir = parent.frame(),
  compress = !ascii, compression_level,
  eval.promises = TRUE, precheck = TRUE)



I remember that you can also find it when you step inside an apply function:


sapply(1:10, function(x)browser())
Called from: FUN(1:10[[1L]], ...)



I apologize for being vague, it's just something that I would like to
understand about the R language (the R word).

Thank you!

Gene

[[alternative HTML version deleted]]

__
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.



--
Claudia Beleites
Dipartimento dei Materiali e delle Risorse Naturali
Università degli Studi di Trieste
Via Alfonso Valerio 6/a
I-34127 Trieste

phone: +39 0 40 5 58-37 68
email: cbelei...@units.it

__
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] The L Word

2011-02-23 Thread Tsjerk Wassenaar
Hi Gene,

It means 'Literal integer'.
So 1L is a proper integer 1, and 0L is a proper integer 0.

Hope it helps,

Tsjerk

On Wed, Feb 23, 2011 at 5:08 PM, Gene Leynes gleyne...@gmail.com wrote:
 I've been wondering what L means in the R computing context, and was
 wondering if someone could point me to a reference where I could read about
 it, or tell me what it's called so that I can search for it myself.  (L by
 itself is a little too general for a search term).

 I encounter it in strange places, most recently in the save documentation.

 save(..., list = character(0L),
      file = stop('file' must be specified),
      ascii = FALSE, version = NULL, envir = parent.frame(),
      compress = !ascii, compression_level,
      eval.promises = TRUE, precheck = TRUE)


 I remember that you can also find it when you step inside an apply function:

 sapply(1:10, function(x)browser())
 Called from: FUN(1:10[[1L]], ...)


 I apologize for being vague, it's just something that I would like to
 understand about the R language (the R word).

 Thank you!

 Gene

        [[alternative HTML version deleted]]

 __
 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.




-- 
Tsjerk A. Wassenaar, Ph.D.

post-doctoral researcher
Molecular Dynamics Group
* Groningen Institute for Biomolecular Research and Biotechnology
* Zernike Institute for Advanced Materials
University of Groningen
The Netherlands

__
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] The L Word

2011-02-23 Thread jim holtman
The notation '1L' mean to interprete the data as an 'integer'.

 str(1)
 num 1
 str(1L)
 int 1

 str(0xaa)
 num 170
 str(0xaaL)
 int 170



On Wed, Feb 23, 2011 at 11:08 AM, Gene Leynes gleyne...@gmail.com wrote:
 I've been wondering what L means in the R computing context, and was
 wondering if someone could point me to a reference where I could read about
 it, or tell me what it's called so that I can search for it myself.  (L by
 itself is a little too general for a search term).

 I encounter it in strange places, most recently in the save documentation.

 save(..., list = character(0L),
      file = stop('file' must be specified),
      ascii = FALSE, version = NULL, envir = parent.frame(),
      compress = !ascii, compression_level,
      eval.promises = TRUE, precheck = TRUE)


 I remember that you can also find it when you step inside an apply function:

 sapply(1:10, function(x)browser())
 Called from: FUN(1:10[[1L]], ...)


 I apologize for being vague, it's just something that I would like to
 understand about the R language (the R word).

 Thank you!

 Gene

        [[alternative HTML version deleted]]

 __
 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.




-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?

__
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] The L Word

2011-02-23 Thread Gene Leynes
Thank you everyone, that makes a lot more sense now.  It's not at all what I
would have guessed! (I thought that it might have to do with scope)

It's one of those little things would add just enough confusion that I would
sort of tune out whenever I saw it. So, I really appreciate having this
little additional nugget of understanding.

On Wed, Feb 23, 2011 at 10:14 AM, Claudia Beleites cbelei...@units.itwrote:

 On 02/23/2011 05:08 PM, Gene Leynes wrote:

 I've been wondering what L means in the R computing context, and was
 wondering if someone could point me to a reference where I could read
 about
 it, or tell me what it's called so that I can search for it myself.  (L by
 itself is a little too general for a search term).

 It means that the number is an integer (a _L_ong integer of 32 bit
 actually)




 I encounter it in strange places, most recently in the save
 documentation.

 save(..., list = character(0L),

  file = stop('file' must be specified),
  ascii = FALSE, version = NULL, envir = parent.frame(),
  compress = !ascii, compression_level,
  eval.promises = TRUE, precheck = TRUE)


 I remember that you can also find it when you step inside an apply
 function:

  sapply(1:10, function(x)browser())
 Called from: FUN(1:10[[1L]], ...)


 I apologize for being vague, it's just something that I would like to
 understand about the R language (the R word).

 Thank you!

 Gene

[[alternative HTML version deleted]]

 __
 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.



 --
 Claudia Beleites
 Dipartimento dei Materiali e delle Risorse Naturali
 Università degli Studi di Trieste
 Via Alfonso Valerio 6/a
 I-34127 Trieste

 phone: +39 0 40 5 58-37 68
 email: cbelei...@units.it


 __
 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.


[[alternative HTML version deleted]]

__
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.