Skip to content

Commit d4ac466

Browse files
reading chp file tree fig update
1 parent 8e365c2 commit d4ac466

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

img/reading/filesystem.jpeg

-122 KB
Binary file not shown.

img/reading/filesystem.png

114 KB
Loading

source/reading.Rmd

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,27 +90,27 @@ with respect to the computer's filesystem base (or *root*) folder, regardless of
9090

9191
Suppose our computer's filesystem looks like the picture in Figure
9292
\@ref(fig:file-system-for-export-to-intro-datascience). We are working in a
93-
file titled `worksheet_02.ipynb`, and our current working directory is `worksheet_02`;
93+
file titled `project3.ipynb`, and our current working directory is `project3`;
9494
typically, as is the case here, the working directory is the directory containing the file you are currently
9595
working on.
9696

9797
```{r file-system-for-export-to-intro-datascience, echo = FALSE, message = FALSE, warning = FALSE, fig.align = "center", fig.cap = "Example file system.", fig.retina = 2, out.width="100%"}
98-
knitr::include_graphics("img/reading/filesystem.jpeg")
98+
knitr::include_graphics("img/reading/filesystem.png")
9999
```
100100

101101
Let's say we wanted to open the `happiness_report.csv` file. We have two options to indicate
102102
where the file is: using a relative path, or using an absolute path.
103103
The absolute path of the file always starts with a slash `/`—representing the root folder on the computer—and
104104
proceeds by listing out the sequence of folders you would have to enter to reach the file, each separated by another slash `/`.
105105
So in this case, `happiness_report.csv` would be reached by starting at the root, and entering the `home` folder,
106-
then the `dsci-100` folder, then the `worksheet_02` folder, and then finally the `data` folder. So its absolute
107-
path would be `/home/dsci-100/worksheet_02/data/happiness_report.csv`. We can load the file using its absolute path
106+
then the `dsci-100` folder, then the `project3` folder, and then finally the `data` folder. So its absolute
107+
path would be `/home/dsci-100/project3/data/happiness_report.csv`. We can load the file using its absolute path
108108
as a string passed to the `read_csv` function.
109109
```{r eval = FALSE}
110-
happy_data <- read_csv("/home/dsci-100/worksheet_02/data/happiness_report.csv")
110+
happy_data <- read_csv("/home/dsci-100/project3/data/happiness_report.csv")
111111
```
112112
If we instead wanted to use a relative path, we would need to list out the sequence of steps needed to get from our current
113-
working directory to the file, with slashes `/` separating each step. Since we are currently in the `worksheet_02` folder,
113+
working directory to the file, with slashes `/` separating each step. Since we are currently in the `project3` folder,
114114
we just need to enter the `data` folder to reach our desired file. Hence the relative path is `data/happiness_report.csv`,
115115
and we can load the file using its relative path as a string passed to `read_csv`.
116116
```{r eval = FALSE}
@@ -119,13 +119,13 @@ happy_data <- read_csv("data/happiness_report.csv")
119119
Note that there is no forward slash at the beginning of a relative path; if we accidentally typed `"/data/happiness_report.csv"`,
120120
R would look for a folder named `data` in the root folder of the computer&mdash;but that doesn't exist!
121121

122-
Aside from specifying places to go in a path using folder names (like `data` and `worksheet_02`), we can also specify two additional
122+
Aside from specifying places to go in a path using folder names (like `data` and `project3`), we can also specify two additional
123123
special places: the *current directory* \index{path!current} and the *previous directory*. \index{path!previous}
124124
We indicate the current working directory with a single dot `.`, and \index{aaaaaacurdirsymb@\texttt{.}|see{path}}
125-
the previous directory with two dots `..`. \index{aaaaaprevdirsymb@\texttt{..}|see{path}} So for instance, if we wanted to reach the `bike_share.csv` file from the `worksheet_02` folder, we could
126-
use the relative path `../tutorial_01/bike_share.csv`. We can even combine these two; for example, we could reach the `bike_share.csv` file using
127-
the (very silly) path `../tutorial_01/../tutorial_01/./bike_share.csv` with quite a few redundant directions: it says to go back a folder, then open `tutorial_01`,
128-
then go back a folder again, then open `tutorial_01` again, then stay in the current directory, then finally get to `bike_share.csv`. Whew, what a long trip!
125+
the previous directory with two dots `..`. \index{aaaaaprevdirsymb@\texttt{..}|see{path}} So for instance, if we wanted to reach the `bike_share.csv` file from the `project3` folder, we could
126+
use the relative path `../project2/bike_share.csv`. We can even combine these two; for example, we could reach the `bike_share.csv` file using
127+
the (very silly) path `../project2/../project2/./bike_share.csv` with quite a few redundant directions: it says to go back a folder, then open `project2`,
128+
then go back a folder again, then open `project2` again, then stay in the current directory, then finally get to `bike_share.csv`. Whew, what a long trip!
129129

130130
So which kind of path should you use: relative, or absolute? Generally speaking, you should use relative paths.
131131
Using a relative path helps ensure that your code can be run
@@ -136,17 +136,17 @@ all of the folders between the computer's root, represented by `/`, and the file
136136
across different computers. For example, suppose Fatima and Jayden are working on a
137137
project together on the `happiness_report.csv` data. Fatima's file is stored at
138138

139-
`/home/Fatima/project/data/happiness_report.csv`,
139+
`/home/Fatima/project3/data/happiness_report.csv`,
140140

141141
while Jayden's is stored at
142142

143-
`/home/Jayden/project/data/happiness_report.csv`.
143+
`/home/Jayden/project3/data/happiness_report.csv`.
144144

145145
Even though Fatima and Jayden stored their files in the same place on their
146146
computers (in their home folders), the absolute paths are different due to
147147
their different usernames. If Jayden has code that loads the
148148
`happiness_report.csv` data using an absolute path, the code won't work on
149-
Fatima's computer. But the relative path from inside the `project` folder
149+
Fatima's computer. But the relative path from inside the `project3` folder
150150
(`data/happiness_report.csv`) is the same on both computers; any code that uses
151151
relative paths will work on both! In the additional resources section,
152152
we include a link to a short video on the

0 commit comments

Comments
 (0)