11

Some possibilities include:

Sys.info()["machine"] == "x86-64"
.Platform$r_arch == "x64"
version$arch == "x86_64"

Is there any reason to prefer one method over another?

Related: detecting operating system in R (e.g. for adaptive .Rprofile files)

Community
  • 1
  • 1
Richie Cotton
  • 118,240
  • 47
  • 247
  • 360
  • I believe those will all fail for at least PowerPC and Itanium 64 bit architecture. `grep`ing `.Platform$r_arch` for "64" might work for most architectures, but why bother when DWin's provided the answer. – jthetzel Jun 22 '12 at 15:51
  • Would probably also fail for Solaris builds. – IRTFM Jun 22 '12 at 20:06

1 Answers1

12

Actually none of those methods would be canonical, which I take to mean "what would Brian Ripley say". Try this:

?.Machine

sizeof.pointer........the number of bytes in a C SEXP type. Will be 4 on 32-bit builds and 8 on 64-bit builds of R.

 64bit <- .Machine$sizeof.pointer == 8
 64bit
 #[1] TRUE

As for your nominations only one of them returns TRUE on my machine:

> Sys.info()["machine"] == "x86-64"
machine 
  FALSE 
> .Platform$r_arch == "x64"
[1] FALSE
> version$arch == "x86_64"
[1] TRUE
IRTFM
  • 258,963
  • 21
  • 364
  • 487