The address of the project in Rstudio

When you open or create a project in RStudio, the working directory is automatically changed to the working directory of the project. However, if you save files or perform work in other subdirectories, it is often convenient to change the working directory. This can be a problem to manage this in every script.

Is there a variable that always points to the root of the project (which is also read by the session with the forked "Knitted HTML" button) that can be used for simplification?

The Knit HTML button will appear to set the working directory to the R Markdown working file. For example, if you have a variable with a name project.rootin yours ./Rprofileand you click "Knit HTML" when you open this script,

```{r}
getwd()
source('./Rprofile')
setwd(project.root)
getwd()
```

the first and last result will be the script directory, and the rest will throw errors.

+4
source share
1 answer

To conclude, as you deduced, you can set the R working directory on the command line as follows:

setwd ("~ / NateProjects")

You can also use the RStudio Files panel to navigate to the directory, and then set it as the working directory from the menu: Session → Set working directory → In the “File panel” field. (There you will see even more options). Or, in the Files area, select More and Install as Working Directory.

, ​​ . , (, , ), - , R-, , . , RStudio . , , , :

http://www.rstudio.com/ide/docs/using/projects

, , :

  • , " " ( "" ). ,

, RStudio, :

  • ( .Rproj) . (. ), .
  • ( .Rproj.user), , (, , ..). .Rbuildignore, .gitignore .., .
  • RStudio "" ( ).
+3

Source: https://habr.com/ru/post/1535212/


All Articles