'Use rstudio::openProject with older version of Rstudio

I use Rstudio Version 0.99.903 and the latest version of library rstudioapi (rstudioapi_0.7).

When trying rstudioapi::openProject('MyProject') I get:

Error: Function openProject not found in RStudio

Here is the code of the rstudioapi function:

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

The issue is most probably that my version of Rstudio is not up to date.

Unfortunately I'm not able to download a later version of Rstudio (I'm restricted on authorized softwares at work), could there be a hack to download the function separately and make it work anyway ?

The functionality of opening a project is already there in Rstudio obviously, so I believe it might be a very simple fix that wouldn't require updating the full software.

I use R version 3.3.1 and Rstudio Version 0.99.903

Digging through the code it seems that the function I'm looking for is .rs.api.openProject.

By browsing through rstudio's source code I found in https://github.com/rstudio/rstudio/blob/master/src/cpp/r/R/Api.R :

.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)")
  )
})

I executed the full file to get all functions updated (probably not the safest decision but as a first iteration).

After this I can move a step further with my rstudioapi::openProject('MyProject') code, but it still fails because I don't have ensureScalarCharacter nor rs_requestOpenProject defined and I don't find those in github.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source