This answer is a summary of the comments above. It is basically just pointers to various help texts, but as evident from OP's attempt with ?L
, it is not always easy to find the relevant help text. I was expecting to find something about L
in ?as.integer
, but no. Hopefully this answer is more useful than a pile of comments.
In the R language
definition
you will find: "We can use the L
suffix to qualify any number
with the intent of making it an explicit integer"
From ?NumericConstants
: "[...] All other numeric constants start
with a digit or period and are either a decimal or hexadecimal
constant optionally followed by L
"
"An numeric constant immediately followed by L
is regarded as an
integer number when possible (and with a warning if it contains a
".")."
"You can combine the "0x
" prefix with the "L
" suffix".
You may also find it useful to check the examples on floating point
vs. integers in the section "Two Kinds Revisited"
here.
"Put capital L
(as in “long”) after a number to make R create it as
an integer".
Not specifically about L
, but always relevant in the floating point
vs. integers context is FAQ7.31: "Why doesn’t R think these numbers are equal?".
Threads with discussions about the efficiency of L
:
Threads on R-help where others have struggled to find documentation about L
, with a possible explanation of why the letter L
, and why L
vs as.integer
in terms of efficiency.
- Difference between 10 and 10L
First William Dunlap:
Why not 10I
for integer? Perhaps because "I
" and "l
" look too similar, perhaps because "i
" and "I
" sound too similar. The "L
" does not mean "long": integers are 4 bytes long.
Then Brian Ripley:
Actually it does: this notation dates from the C language on 16-bit
computers where integers were 16-bits and longs were 32-bit (and R has
no 'long' type).
The author of this in R never explained why he chose the notation, but
it is shorter than as.integer(10)
, and more efficient as the coercion is
done at parse time.
The L Word
Discussion about the efficiency in different situations, with some benchmarkings.
R history: Why 'L; in suffix character ‘L’ for integer constants?
More discussions here.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…