10

On Win7 I have both 32 bit and 64 bit R installed. Because one can't ODBC to 32 bit MS Access from 64 bit R, I want to source an R script using the 32 bit version of R. From this SO question I understand that I can launch 32 bit R using system() with

system(paste0(Sys.getenv("R_HOME"), "/bin/i386/R.exe"), wait = FALSE, invisible = FALSE)

This launches R in a terminal. Is it also possible to source an R script from a system() call?

I wondered whether R CMD BATCH would be a possibility, but I can't see a way to set it to 32 bit R.

Community
  • 1
  • 1
r.bot
  • 5,309
  • 1
  • 34
  • 45

1 Answers1

9

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.

TARehman
  • 6,659
  • 3
  • 33
  • 60
  • 2
    As an addendum to this, it's possibly worth noting that if the file path of `your_rfile.R` has a space in it, then it will need shell quoting. The following should work: `system(paste0(Sys.getenv("R_HOME"), "/bin/i386/R.exe ", sqQuote("C:\\path to\\file.R")), wait = FALSE, invisible = FALSE)` – r.bot Aug 21 '15 at 10:19
  • 1
    @r.bot except `Rscript.exe` instead of `R.exe` and `shQuote` rather than `sqQuote` – Hack-R Mar 18 '16 at 13:46