Skip to content

Commit ff809d7

Browse files
committed
updated policies and api lecture
1 parent 4e48293 commit ff809d7

File tree

6 files changed

+336
-192
lines changed

6 files changed

+336
-192
lines changed

content/lecture/api.Rmd

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: "Application programming interfaces"
33
author: Tad Dallas
44
date:
5-
output: pdf_document
5+
output: html_document
66
---
77

88

@@ -94,7 +94,7 @@ vonInfo <- jsonlite::fromJSON(content(von, "text"), simplifyVector = FALSE)
9494
```
9595

9696

97-
This output is a list of length 4, each containing a nested list. It is not the cleanest output, but it rarely is. But all the information you could want is buried somewhere here.
97+
This output is a list of length 8, each containing a nested list. It is not the cleanest output, but it rarely is. But all the information you could want is buried somewhere here.
9898

9999

100100
This apply statement gets information on the title of each of the works returned from our search for "Vonnegut".
@@ -151,6 +151,61 @@ vonTitle <- sapply(vonInfo2[[8]], function(x){
151151

152152

153153

154+
Time to read a bit of API documentation! The Open Library API documentation is at https://openlibrary.org/developers/api. For this problem, I want you to query by subject and extract relevant details with your knowledge of `httr`/`jsonlite` and data.frame/list objects. The documentation for subject queries is at:
155+
156+
https://openlibrary.org/dev/docs/api/subjects
157+
158+
159+
160+
161+
162+
How many books were published on the `subject` of love?
163+
164+
165+
```{r}
166+
167+
168+
169+
```
170+
171+
172+
Who has written the most books on love?
173+
174+
175+
```{r}
176+
177+
178+
179+
```
180+
181+
182+
183+
184+
185+
186+
187+
The Art Institute of Chicago also has an open API (https://api.artic.edu/docs/#quick-start).
188+
189+
Create a histogram of the `colorfulness` score of the first 1000 paintings (https://api.artic.edu/api/v1/artworks).
190+
191+
*Hint*: you will need to use the `page` and `limit` arguments to get 1000 paintings.
192+
193+
194+
```{r}
195+
196+
197+
```
198+
199+
200+
201+
202+
203+
204+
205+
206+
207+
208+
154209
> Side fun note: You can access GitHub info through API calls as well
155210
156211
```{r}
@@ -164,8 +219,6 @@ tadInfo <- jsonlite::fromJSON(content(tad, "text"), simplifyVector = FALSE)
164219

165220

166221

167-
168-
169222
### Class problem:
170223

171224
How long as Tad been on GitHub?
@@ -190,6 +243,30 @@ That list (`tadInfo`) also has some links to other API calls that could be made.
190243

191244

192245

246+
There are some arguments that can be passed to API calls (every API ideally has good documentation and goes over this). For instance, GitHub has page limits on the number of results reported, but you can set the number of results per page using the `per_page` argument. Using this, write a loop to assemble a data.frame of followers of `torvalds` (the creator of Linux and git).
247+
248+
**Hints**: you'll likely need to loop over multiple calls, since `per_page` is capped at 100, and you may also need to specify `page` argument.
249+
250+
```{r class.source = 'fold-hide'}
251+
252+
253+
254+
```
255+
256+
257+
258+
259+
260+
261+
262+
263+
264+
265+
266+
267+
268+
269+
193270

194271
## A more biological example
195272

0 commit comments

Comments
 (0)