Skip to content

Commit

Permalink
Reading index
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorcampbell committed Nov 16, 2023
1 parent a321df2 commit e4b5de2
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions source/reading.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Suppose our computer's filesystem looks like the picture in Figure
\@ref(fig:file-system-for-export-to-intro-datascience). We are working in a
file titled `worksheet_02.ipynb`, and our current working directory is `worksheet_02`;
typically, as is the case here, the working directory is the directory containing the file you are currently
working on.\index{Happiness Report}
working on.

```{r file-system-for-export-to-intro-datascience, echo = FALSE, message = FALSE, warning = FALSE, fig.cap = "Example file system.", fig.retina = 2, out.width="100%"}
knitr::include_graphics("img/reading/filesystem.jpeg")
Expand Down Expand Up @@ -120,8 +120,9 @@ Note that there is no forward slash at the beginning of a relative path; if we a
R would look for a folder named `data` in the root folder of the computer—but that doesn't exist!

Aside from specifying places to go in a path using folder names (like `data` and `worksheet_02`), we can also specify two additional
special places: the *current directory* and the *previous directory*. We indicate the current working directory with a single dot `.`, and
the previous directory with two dots `..`. So for instance, if we wanted to reach the `bike_share.csv` file from the `worksheet_02` folder, we could
special places: the *current directory* \index{path!current} and the *previous directory*. \index{path!previous}
We indicate the current working directory with a single dot `.`, and \index{aaaaaacurdirsymb@\texttt{.}|see{path}}
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
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
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`,
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!
Expand Down Expand Up @@ -1202,15 +1203,15 @@ That should be more than enough for our purposes in this section.

#### Accessing the NASA API {-}

The NASA API is what is known as an *HTTP API*: this is a particularly common
The NASA API is what is known as an *HTTP API*: \index{API!HTTP} this is a particularly common
kind of API, where you can obtain data simply by accessing a
particular URL as if it were a regular website. To make a query to the NASA
API, we need to specify three things. First, we specify the URL *endpoint* of
API, we need to specify three things. First, we specify the URL *endpoint* of \index{API!endpoint}
the API, which is simply a URL that helps the remote server understand which
API you are trying to access. NASA offers a variety of APIs, each with its own
endpoint; in the case of the NASA "Astronomy Picture of the Day" API, the URL
endpoint is `https://api.nasa.gov/planetary/apod`. Second, we write `?`, which denotes that a
list of *query parameters* will follow. And finally, we specify a list of
list of *query parameters* \index{API!query parameters} will follow. And finally, we specify a list of
query parameters of the form `parameter=value`, separated by `&` characters. The NASA
"Astronomy Picture of the Day" API accepts the parameters shown in
Figure \@ref(fig:NASA-API-parameters).
Expand Down Expand Up @@ -1249,7 +1250,8 @@ Rho Ophiuchi","url":"https://apod.nasa.gov/apod/image/2307/STScI-01_RhoOph1024.p

Neat! There is definitely some data there, but it's a bit hard to
see what it all is. As it turns out, this is a common format for data called
*JSON* (JavaScript Object Notation). We won't encounter this kind of data much in this book,
*JSON* (JavaScript Object Notation). \index{JSON}\index{JavaScript Object Notation|see{JSON}}
We won't encounter this kind of data much in this book,
but for now you can interpret this data as `key : value` pairs separated by
commas. For example, if you look closely, you'll see that the first entry is
`"date":"2023-07-13"`, which indicates that we indeed successfully received
Expand All @@ -1260,6 +1262,7 @@ the `httr2` package, and construct the query using the `request` function, which
you will recognize the same query URL that we pasted into the browser earlier.
We will then send the query using the `req_perform` function, and finally
obtain a JSON representation of the response using the `resp_body_json` function.
\index{httr2!req_perform}\index{httr2!resp_body_json}

<!-- we have disabled the below code for reproducibility, with hidden setting
of the nasa_data object. But you can reproduce this using the DEMO_KEY key -->
Expand Down

0 comments on commit e4b5de2

Please sign in to comment.