将 rstudio::openProject 与旧版本的 Rstudio 一起使用

Use rstudio::openProject with older version of Rstudio

我使用 Rstudio Version 0.99.903 和最新版本的库 rstudioapi (rstudioapi_0.7)。

当尝试 rstudioapi::openProject('MyProject') 我得到:

Error: Function openProject not found in RStudio

这里是rstudioapi函数的代码:

rstudioapi::openProject
function (path = NULL, newSession = FALSE) 
{
    callFun("openProject", path, newSession)
}
<environment: namespace:rstudioapi>

问题很可能是我的 Rstudio 版本不是最新的。

不幸的是,我无法下载 Rstudio 的更高版本(我在工作中受限于授权软件),是否可以单独下载该功能并使其正常运行?

打开项目的功能显然已经在 Rstudio 中,所以我相信这可能是一个非常简单的修复,不需要更新完整的软件。

我用R version 3.3.1Rstudio Version 0.99.903

通过代码挖掘,我正在寻找的功能似乎是 .rs.api.openProject

通过浏览我在 https://github.com/rstudio/rstudio/blob/master/src/cpp/r/R/Api.R 中找到的 rstudio 的源代码:

.rs.addApiFunction("openProject", function(path = NULL,
                                           newSession = FALSE)
{
  # default to current project directory (note that this can be
  # NULL if the user is not within an RStudio project)
  if (is.null(path))
    path <- .rs.getProjectDirectory()

  path <- .rs.ensureScalarCharacter(path)

  # attempt to initialize project if necessary
  rProjFile <- .rs.api.initializeProject(path)

  # request that we open this project
  invisible(
    .Call("rs_requestOpenProject",
          rProjFile,
          newSession,
          PACKAGE = "(embedding)")
  )
})

我执行了完整文件以更新所有功能(可能不是最安全的决定,但作为第一次迭代)。

在此之后我可以进一步使用我的 rstudioapi::openProject('MyProject') 代码,但它仍然失败,因为我没有定义 ensureScalarCharacter 也没有 rs_requestOpenProject 而且我没有找到github.

中的那些

不幸的是,您的旧版本 RStudio 无法实现您想要执行的操作。 rs_requestOpenProject 只是在您的 IDE 版本中不存在,并且由于它是本机代码,因此无法对其进行修补(对于您的组织来说,这比仅更新 IDE).