RStudio and .Rprofile execution Timing

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 by putting the following at the end of my .Rprofile:

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

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?

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


Not sure why no feedback yet. Is there something else I need to include in this question to help it along?

I believe attempts to use rstudioapi in a .Rprofile can fail simply because RStudio hasn't yet fully finished initialization, and so the rstudioapi package believes that RStudio is not actually active.

Can you file this as an issue on the rstudioapi repository?