如何在 RStudio 中动态切换 R 架构 [英] How switch R architectures dynamically in RStudio

查看:27
本文介绍了如何在 RStudio 中动态切换 R 架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 RStudio 中有一个 Tools 菜单,它允许您在 Global Options 下选择已安装的 R 版本/架构.

In RStudio there's a Tools menu which allows you to select an installed version/architecture of R under Global Options.

这很好,但我的问题是,顾名思义,它是一个全局选项,因此一旦您选择了不同的架构(或版本号),您就必须重新启动 RStudio它适用于所有您的 RStudio 实例和项目.

That's great, but my issue with that is that, as the name implies, it is a Global option, so once you select a different architecture (or version number) you then have to restart RStudio and it applies to all of your RStudio instances and projects.

这对我来说是个问题,因为:

This is a problem for me because:

  • 我在给定项目中有一些脚本严格要求使用 32 位 R,因为它们与 32 位数据库(例如 Hortonworks 的 Hadoop)交互
  • 我有其他脚本在同一个项目中,它们严格要求 64 位 R,因为 (a) 某些软件包的可用性和 (b) 32 位 R 上的内存限制非常小我的操作系统
  • I have some scripts within a given project that strictly require 32-bit R due to the fact that they're interfacing with 32-bit databases, such as Hortonworks' Hadoop
  • I have other scripts within the same project which strictly require 64-bit R, due to (a) availability of certain packages and (b) memory limits being prohibitively small in 32-bit R on my OS

我们可以称之为问题 #1",这也是一个问题,因为我有一些需要特定架构的项目,尽管项目中的所有脚本都使用相同的架构(理论上应该更容易解决问题)我们可以称之为问题#2").

which we can call "Issue #1" and it's also a problem because I have certain projects which require a specific architecture, though all the scripts within the project use the same architecture (which should theoretically be an easier to solve problem that we can call "Issue #2").

如果我们能解决问题 #1,那么问题 #2 也能解决.如果我们能解决问题 #2,即使问题 #1 没有解决,我也会过得更好.

If we can solve Issue #1 then Issue #2 is solved as well. If we can solve Issue #2 I'll still be better off, even if Issue #1 is unsolved.

我基本上是在问是否有人有一个 hack、变通方法或更好的工作流程来解决这种频繁切换架构的需求和/或需要在不同的 R/RStudio 会话中同时为不同的项目定期运行不同的架构基础.

I'm basically asking if anyone has a hack, work-around, or better workflow to address this need for frequently switching architectures and/or needing to run different architectures in different R/RStudio sessions simultaneously for different projects on a regular basis.

我知道此功能可能代表对 RStudio 的功能请求,如果此问题因此不适用于 StackOverflow,请告诉我,我将删除它.我只是想很多其他人可能都有这个问题,所以也许有人找到了解决方法/黑客?

I know that this functionality would probably represent a feature request for RStudio and if this question is not appropriate for StackOverflow for that reason then let me know and I'll delete it. I just figured that a lot of other people probably have this issue, so maybe someone has found a work-around/hack?

推荐答案

没有简单的方法可以做到这一点,但有一些解决方法.您可能会考虑通过 system2 调用 Rscript.exe 从 R 的当前位风格启动正确的 R 位风格,例如(未经测试的代码):

There's no simple way to do this, but there are some workarounds. One you might consider is launching the correct bit-flavor of R from the current bit-flavor of R via system2 invoking Rscript.exe, e.g. (untested code):

source32 <- function(file) {
  system2("C:\\Program Files\\R\\R-3.1.0\\bin\\i386\\Rscript.exe", normalizePath(file)) 
}
...
# Run a 64 bit script
source("my64.R")

# Run a 32 bit script
source32("my32.R")

当然,这并没有真正为您提供 32 位交互式会话,而是能够以 32 位方式运行代码.

Of course that doesn't really give you a 32 bit interactive session so much as the ability to run code as 32 bit.

另一个提示:如果您在启动 RStudio 时按住 CTRL,您可以选择 R 风格和位数以在启动时启动.如果您经常切换,这将为您节省一些时间.

One other tip: If you hold down CTRL while launching RStudio, you can pick the R flavor and bitness to launch on startup. This will save you some time if you're switching a lot.

这篇关于如何在 RStudio 中动态切换 R 架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆