You could save the part of your code that you wish to execute using the 32-bit executable into a new script. For example, I have a script called myscript.r
which will just print which version of the R executable (64 or 32-bit) which was used to run it:
cat(as.character(version[2]))
Of course you could replace this with the part of your code dealing with RODBC
.
Now the main way to programmatically run a script with a custom executable is to invoke a command to the OS terminal or shell. This command should contain:
- Which executable to invoke, in our case R 32-bit (the
Rscript.exe
file contained in the i386
folder of your R_HOME
directory)
- Arguments accepted by this executable, such as the path to the R script we want to run using this executable.
The path of myscript
is "c:/gp/trash/myscript.r"
, and my 32-bit R executable is
paste0(Sys.getenv("R_HOME"), "/bin/i386/Rscript.exe)
C:/PROGRA~1/R/R-40~1.4/bin/i386/Rscript.exe
I can run this script using:
myscript <- "c:/gp/trash/myscript.r"
output <- system(paste0(Sys.getenv("R_HOME"), "/bin/x64/Rscript.exe ", myscript), wait = FALSE, invisible = FALSE, intern = T)
output
[1] "x86_64"
output_32 <- system(paste0(Sys.getenv("R_HOME"), "/bin/i386/Rscript.exe ", myscript), wait = FALSE, invisible = FALSE, intern = T)
output_32
[1] "i386"
So as you can see we're executing this script from two different executables. In practice I'd suggest to save the results of your ODBC queries to a file, which you can read in your main x64
R session.
Just a little vocabulary if you don't know some of these terms:
The terms terminal or shell are often used interchangeably. In RStudio, if you click on the terminal tab next to console, you'll be able to enter commands that will be processed by a shell.
- Shell commands are instructions that instruct the system to do some action.
- A shell is a user interface for accessing the services of an operating system.
- A terminal is a wrapper program that runs a shell and allows us to enter commands.
sources: terminal, console and cli, shell commands, scripting with r, this stackoverflow answer