R handles numbers in different ways. In R both integers and double precision float defaults to their 32 bit version.
As pointed out by Andrey, there are two different types of numbers in R.
- Literals
1L, 2L, 3L, ....
, this is equivalent to as.integer(1)
- regular numbers (1, 2, 3.4, any number really)
As well as their complex counterparts.
Literals are integers as such
typeof(1) #double
class(1) #numeric
typeof(1L) #integer
class(1L) #integer
is well defined. However upon calculation, if any part of the calculation is not stored as a lower or equal type than integer, it will automatically be converted to a double:
typeof(1L + 1L) #integer
typeof(1L + 1) #double
typeof(1L + TRUE) #integer
typeof(1L * 3) #double
typeof(1L * 3L) #integer
One should note however, as R runs with 32 bit variables, these have a limited range, compared to python 3.x. However one can get around the 32 bit variables ( in most cases! ) by using the packages bit64
for 64 bit integers and Rmpfr
which gives an interface for arbitrary floating point precision (according to their documentation).
Edit
I wrongly stated that "In R both integers and double precision float defaults to their 32 bit version". This is not the case for double precision variables, which default to a their 64 bit counterpart in almost all releases of R nowadays.