How to Know If R Is Running on 64 Bits Versus 32

How can I know if R is running on 64 bits versus 32?

Here are a few ways:

  • Sys.getenv("R_ARCH") returns either "/i386" or "/x64" at least on my Windows system (but not on my Ubuntu system where it returns an empty string)

  • Sys.info()[["machine"]] returns "x86_32" or "x86_64" on my Windows and Ubuntu systems.

Updated: With additional method.

RStudio running on 32 bit on a 64 bit OS with 64 bit R installation

RStudio (the front-end) is a 32bit application, but it understands how to speak with both 32-bit and 64-bit R sessions. The bitness of the RStudio front-end does not affect performance of the R backend.

If R's sessionInfo() reports that a 64-bit version of R is running, then 64-bit registers and all will be used.

Source R script using 32 bit R from 64 bit RStudio

I think you want to use Rscript.exe to run the file, rather than R.exe. You can do this by just using /bin/i386/Rscript.exe your_rfile.R - this is how I would execute R code from the command line in Windows.

Check if my program is running in 32 bit mode on a 64bit machine, if running in 64bit - how do I force it to be 32bit

One plausible explanation for the discrepency is that you're deploying the output of a different build configuration.

Could it be that you setup your Debug configuration to target x86, but didn't make the change to the Release configuration, thereby leaving it as AnyCPU and deploying it to production?

Running R function with arguments in 32 bit R, inside 64 bit R

I managed to find a solution myself, by modifying Roman Luštrik's solution.

Following his example we have the script called test_script.R:

args <- commandArgs(trailingOnly = TRUE)

test.function <- function(x) {
print(x)
}

args.run <- list(x = args)
mydata <- do.call(test.function, args = args.run)
save(mydata, file = "Data.Rda") # If you need the output to an R object

Then in another script that runs 64 bit R, we can run this function in 32 bit R by:

pathIn32BitRScript <- '"C:/Some path/test_script.R"'
system(paste0(Sys.getenv("R_HOME"), "/bin/i386/Rscript.exe", pathIn32BitRScript, " ", "Hello world") )
load("Data.Rda") # Loads the results into an object called mydata
invisible(file.remove("Data.Rda")) # Deletes the file we created

In this example we have x = "Hello World". In case you have spaces in your path you will need the double quotes as I have in this example.



Related Topics



Leave a reply



Submit