Newly setup Rstudio project working directory

I know how to start a new project in Rstudio. I've been doing that for the past months in my work laptop. However, when I started an R project in my personal laptop I noticed that the default working directory wasn't where I had setup my project directory. I know this is not supposed to happen because I haven't seen an issue like this in my work laptop.

I searched through google and stackoverflow, but I could find anything useful. The only question that I found similar to my problem is the one here. OP answered his own question saying that he modified the Rprofile.site. But I can't do the same with mine. Any pointers please.

Hey @Dieg11 - thanks for posting!

When you say default working directory, do you mean the folder that RStudio points to when you are not using an R project?

It sounds like you were expecting RStudio to point to your project directory but it isn't. Can you confirm that the project is open? In the upper righthand corner, you should see your project name next to a blue cube R project icon.

Yes, I expect RStudio project to point to my project directory, but it's instead pointing to the 'original directory', that is the directory when I am not inside a project. I can confirm that the project is open as I can see its name next to the blue cube. I have no problem in my work laptop, but I do in my personal laptop.

Gotcha. I've got a couple more diagnostic questions - thanks for hanging in there with me!

  • Can you describe how you know the working directory is not pointing to the project directory?

  • Is this behavior specific to one project? Or happens across all projects?

  • What version of RStudio do you have running?

  • Have you tried restarting RStudio?

Answers to the bullets in order:

  1. When I open an Rstudio project, I type getwd() inside the console and it doesn't point to the project directory.
  2. This behavior happens across all projects.
  3. I have Rstudio version 1.1.442.
  4. I have restarted RStudio.

OK @Dieg11 thanks for the additional information. One more question... the output of this function should be the same as your project directory:

rprojroot::find_rstudio_root_file()

I just created a test project on my desktop, have made sure it is opened, and have checked both the find_rstudio_root_file() and getwd() output:

> getwd()
[1] "/Users/prenercg/Desktop/test"
> rprojroot::find_rstudio_root_file()
[1] "/Users/prenercg/Desktop/test"

Do you mind running that rprojroot::find_rstudio_root_file() function and sharing the results?

When I run rprojroot::find_rstudio_root_file() inside my project I get the following error message:

Error: No root directory found in C:/xxxx/xxx/xxx/xxx or its parent directories. Root criterion: contains a a file matching [.]Rproj$ with contents matching ^Version: in the first line.

Thanks @Dieg11 - my first piece of advice for addressing this is to upgrade RStudio to the latest version. There is a slightly newer version out there (1.1.456). Can you upgrade on your machine and then see if this behavior persists?

Thanks. I will upgrade later and share my results.

1 Like

Hello. I just wanted to update you that I deleted Rstudio and installed the Rstudio version 1.1.456, but the problem still persists.

Thanks for following up @Dieg11 - if you have a project opened (verified by looking at the upper righthand corner of the screen that shows the project name) and rprojroot::find_rstudio_root_file() still returns an error, can you follow-up with your operating system name and version as well as the version of R you use?

I would also recommend uploading a screenshot that shows both the rprojroot::find_rstudio_root_file() error and the project open in the upper righthand corner. That will be helpful information along with the output of devtools::session_info() or, at least, sessionInfo().

Hi thanks for your continued support. I use Windows 10 and R version 3.4.
Here's a screenshot of my session:

Thanks @Dieg11! It looks like you are missing a dependency for devtools - can you run install.packages("Rcpp") and then try to get that session_info() output as well?

One more piece of follow-up @Dieg11 - once you've got the devtools::session_info() output, I would open a new issue on RStudio's GitHub "Issues" tab. Include the screenshot you showed me, which confirms that you've got the workflow down and this is more likely to be a bug, and the other info you've pulled together (OS, version of R/RStudio, devtools::session_info() output). You can also link back to this thread if you like.

Hi. Here's the output of those two functions.

You might consider resetting your project's state;

If you are using RStudio Projects, we'd also recommend resetting the project-specific state if you're having issues - you can do this by navigating to the Project's folder in your file browser, and renaming the .Rproj.user directory there.

Also check out the RStudio support guide,

You can use an .Rprofile to ensure your working directory is set to your project's directory.

1 Like

Note the message output during install, that says "unable to move temporary installation to <...>". This implies that the package was downloaded, but wasn't successfully copied into your library paths.

This is a frustrating Windows issue, and can occur if a different instance of R / RStudio is open, and has loaded that package. The easiest way to verify that this might be the case would be:

  1. Restart your computer,
  2. Open R / RStudio,
  3. Without loading any other packages, try once more to install.packages("Rcpp").

Let us know if you still see the same output on install.

1 Like

Can you explain exactly what you mean here? If you have a call to e.g. setwd("~/") in a startup profile (e.g. .Rprofile or .Rprofile.site), then that could explain the behavior you're seeing. Why aren't you able to modify this file? Does this file contain the setwd() call that could explain why you're seeing this issue?

1 Like

I can't modify the file because when I search for it I can't find it.