[英]R, RStudio: Programmatically switch between 32-bit and 64-bit versions of R
Is there a function that, within RStudio, restarts the R console in 64-bit mode or 32-bit mode without re-opening RStudio (or at least automatically re-opening it if that can't be avoided)? Is there a function that, within RStudio, restarts the R console in 64-bit mode or 32-bit mode without re-opening RStudio (or at least automatically re-opening it if that can't be avoided)?
I commonly run in 32-bit when using RODBC
so that I can retrieve data from an Access database, but would like to otherwise leverage the capabilities of 64-bit mode for all other tasks while still in RStudio.在使用RODBC
时,我通常以 32 位运行,以便我可以从 Access 数据库中检索数据,但我希望在 RStudio 中的所有其他任务中利用 64 位模式的功能。
You could save the part of your code that you wish to execute using the 32-bit executable into a new script.您可以将希望使用 32 位可执行文件执行的部分代码保存到新脚本中。 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:例如,我有一个名为myscript.r
的脚本,它将打印用于运行它的 R 可执行文件(64 位或 32 位)的哪个版本:
cat(as.character(version[2]))
Of course you could replace this with the part of your code dealing with RODBC
.当然,您可以将其替换为处理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 .现在,使用自定义可执行文件以编程方式运行脚本的主要方法是调用 OS终端或shell的命令。 This command should contain:该命令应包含:
Rscript.exe
file contained in the i386
folder of your R_HOME
directory)调用哪个可执行文件,在我们的例子中是 R 32 位( Rscript.exe
目录的i386
文件夹中包含的R_HOME
文件) The path of myscript
is "c:/gp/trash/myscript.r"
, and my 32-bit R executable is myscript
的路径是"c:/gp/trash/myscript.r"
,我的 32 位 R 可执行文件是
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.在实践中,我建议将 ODBC 查询的结果保存到文件中,您可以在主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.术语终端或 shell 经常互换使用。 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 .在 RStudio 中,如果您单击控制台旁边的终端选项卡,您将能够输入将由shell处理的命令。
sources: terminal, console and cli , shell commands , scripting with r , this stackoverflow answer来源: 终端、控制台和 cli , shell 命令, 使用 r 编写脚本,这个 stackoverflow 答案
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.