Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to reliably use rstudioapi in the .rprofile startup script #100

Open
justacec opened this issue May 24, 2018 · 4 comments
Open

Unable to reliably use rstudioapi in the .rprofile startup script #100

justacec opened this issue May 24, 2018 · 4 comments

Comments

@justacec
Copy link

I am executing RStudio in an home directory mounted on a windows UNC file path. I am aware that RStudio does not play nice with this so at the end of my .Rprofile I chdir('u:') which goes to a mapped "u" drive. This has been working great. However, when I open a project, it does not set the working directory to the correct path. It leaves it as "U:". I thought I had a fix for this by putting the following at the end of my .Rprofile:

tdir = 'u:/'
if(rstudioapi::isAvailable()) {
  if(!is.null(rstudioapi::getActiveProject())) tdir = rstudioapi::getActiveProject()
}
setwd(tdir)

However, this does not work. When that code chunk is running, it thinks that RStudio is not running. I determined this by putting a cat(rstudioapi::getActiveProject()) outside the if statement and got a response "Error: RStudio not running".

What can I do so that RStudio correctly opens the project root as the working directory?

A possible solution would be the execution of a different startup script, which is user customizable, after RStudio has been guaranteed to be completely started.

I am running RStudio version 1.1.442 on a Windows Server 2008 R2 OS.

@vnijs
Copy link

vnijs commented Oct 6, 2018

Similar question. Trying to run a shiny app on Rstudio startup that needs information about rstudioapi::getActiveProject(). Any updates on this perhaps?

@kguidonimartins
Copy link

Similar problem here. I tried using rstudioapi::navigateToFile("report.Rmd"), but I did not succeed.

@gtritchie
Copy link
Member

This is a known issue with RStudio; the rstudio internals are not yet available when .rprofile is executing.

This issue tracks adding a way to accomplish this: rstudio/rstudio#1579

@julioevi
Copy link

julioevi commented Jul 20, 2022

we can use hooks now

setHook("rstudio.sessionInit", function(newSession) {
    if (newSession)
        rstudioapi::filesPaneNavigate(getwd())
}, action = "append")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants