-
Notifications
You must be signed in to change notification settings - Fork 1
/
pathdirectories.Rmd
68 lines (53 loc) · 2.16 KB
/
pathdirectories.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Paths and directories
* The path of a file/directory is its **location/address** in the file system.
* Your home directory is the one that hosts your personal folder:
+ for CRG users: **/nfs/users/[yourgroup]/[yourusername]**
+ your **Home** is where your store your data, analysis, etc. You are the only one who can **write** in this folder (apart from the system administrator, if needed).
## Tree of directories
<a href="https://sbcrg.github.io/CRG_RIntroduction/images/tree_directories.png"><img src="images/tree_directories.png" alt="rstudio logo" width="1000"/></a>
<br>
<font size="12"> <b>~</b></font>: shortcut to the home directory
<br>
<font size="12"> <b>.</b></font>: current directory
<br>
<font size="12"> <b>..</b></font>: one directory up the tree
In this example, **Rcourse** is a sub-directory of **sbonnin**, which in turn is a sub-direcory of **bi**, and so on.
## Navigate the tree of directory with the R console
* Get the path of the current directory (know where you are working at the moment) with <b>getwd</b> (get working directory):
```{r, eval=FALSE}
getwd()
```
Hit **Enter/Return** to execute getwd() in the R console.
* Change working directory with **setwd** (set working directory)<br>
(in a Windows or MAC OS system, you would typically **double-click** to reach sub-directories). <br>
Here we use **commands/fonctions** in the **R console**:<br>
Go to a directory giving the **absolute path** (the entire address):
```{r, eval=FALSE}
setwd("/users/bi/sbonnin/Rcourse")
```
Same as:
```{r, eval=FALSE}
setwd("~/Rcourse")
```
Go to a directory giving the **relative path**. For example, if you are in **Rcourse**, you can either go to **Module1** using the absolute path:
```{r, eval=FALSE}
setwd("/users/bi/sbonnin/Rcourse/Module1")
```
or the relative path:
```{r, eval=FALSE}
setwd("Module1")
```
You are now in: "~/Rcourse/Module1" (check it with getwd() !).
<br>
Move one directory "up" the tree:
```{r, eval=FALSE}
setwd("..")
```
You are now in: "~/Rcourse"
**HANDS-ON**
1. Execute the following command in the R console:
```{r, eval=FALSE}
setwd("/")
```
2. Where are you now? (use getwd())
3. Find your way back to the **Module1** folder