AstridB
AstridB

Reputation: 51

How to set the default working directory of my R project to my project directory?

I have started to use R Projects, but when I start a new project (either in a new or existing directory), the default working directory is not set to that folder (I thought that should be the case, right? I read it here).

What happens instead is that it goes to my home folder, like:

>getwd()
[1] "/home/user"

I can change my working directory manually to the project folder with setwd(), but when I restart RStudio, it is going back to the home folder again, not the project folder.

Any ideas how to fix this?

Pretty basic question probably, but I have not found the answer yet, and I am new to the projects part of RStudio, so I am not sure if this is an issue in my settings or something...

> sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.3 LTS

Upvotes: 2

Views: 13586

Answers (3)

AstridB
AstridB

Reputation: 51

I found my mistake. For some reason I had setwd("~") in my Rprofile.site document... I removed it and tried again with starting new projects in RStudio. Now getwd() shows the correct folder of the current project.

Upvotes: 3

Biocrazy
Biocrazy

Reputation: 401

To do it directly:

setwd("/PATH/TO/YOUR/FOLDER")

or:

Files -> (search and select your folder) -> More -> Set as working directory

Upvotes: -1

Konrad Rudolph
Konrad Rudolph

Reputation: 546083

but when I restart RStudio, it is going back to the home folder again, not the project folder.

This shouldn’t happen. The RStudio documentation for projects states:

When a project is opened within RStudio the following actions are taken: […]

  • The current working directory is set to the project directory.

I can verify that this works as documented on macOS with RStudio 1.0.153. If this isn’t working for you, you should report a bug.

Upvotes: 1

Related Questions