我使用Rstudio Version 0.99.903和最新版本的库rstudioapi (rstudioapi_0.7)。
在尝试rstudioapi::openProject('MyProject')时,我得到:
错误:函数openProject在RStudio中找不到
下面是rstudioapi函数的代码:
rstudioapi::openProject
function (path = NULL, newSession = FALSE)
{
callFun("openProject", path, newSession)
}
<environment: namespace:rstudioapi>问题很可能是我的Rstudio版本并不是最新的。
不幸的是,我无法下载更高版本的Rstudio (我在工作中只能使用授权软件),是否可以单独下载该功能并使其正常工作?
显然,在Rstudio中,打开项目的功能已经存在,所以我相信这可能是一个非常简单的修复,不需要更新整个软件。
我使用R version 3.3.1和Rstudio 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中找到这些代码。
发布于 2022-03-01 22:54:48
不幸的是,您试图用旧版本的RStudio所做的事情是不可能的。rs_requestOpenProject只是不存在于您的IDE版本中,而且由于它是本机代码,所以没有办法对它进行修补(对您的组织来说,这比更新IDE更好)。
https://stackoverflow.com/questions/48747464
复制相似问题