+ - 0:00:00
Notes for current slide
Notes for next slide

ETC1010: Data Modelling and Computing

Lecture 6B: Functions

Dr. Nicholas Tierney & Professor Di Cook

EBS, Monash U.

2019-09-06

1 / 69

Recap

  • style (it's important!)
  • ed quiz
2 / 69

File Paths and organising yourself

  • It's important when you start working on your own machine that you understand file storage hygiene.
  • It helps prevent unexpected problems and makes you more productive
  • You'll spend less time fighting against strange file paths.
  • Not sure what a file path is? We'll explain that as well.
3 / 69

Your Turn

Discuss:

  1. What your normal "workflow" is for starting a new project
  2. Possible challenges that might arise when maintaining your project
4 / 69

A Mantra: When you start a new project - Open a new RStudio project

setwd("c:/really/long/file/path/to/this/directory)
  • What do you think the setwd code does?
5 / 69

What does setwd() do?

  • "set my working directory to this specific working directory".

  • It means that you can read in data and other things like this:

data <- read_csv("data/mydata.csv")
  • Instead of
data <- read_csv("c:/really/long/file/path/to/this/directory/data/mydata.csv")
6 / 69

What does setwd() do?

  • This has the effect of making the file paths work in your file
  • This is a problem because, among other things, using setwd() like this:
    • Has 0% chance of working on someone else's machine (this includes you in >6 months)
    • Your file is not self-contained and portable. (Think: "What if this folder moved to /Downloads, or onto another machine?")
  • To get this to work, you need to hand edit the file path to your machine.
  • This is painful. And when you do this all the time, it gets old, fast.
7 / 69

What even is a file path?

  • The machine-readable directions to where files on your computer live.
  • So, this file path:
/Users/njtierney/rmd4sci-materials/demo-gapminder.Rmd

Describes the location of the file "demo-gapminder.Rmd".

8 / 69

What even is a file path?

We could visualise the path

/Users/njtierney/rmd4sci-materials/demo-gapminder.Rmd

as:

users
└── njtierney
└── rmd4sci-materials
└── demo-gapminder.Rmd
9 / 69
  • To read in the gapminder.csv file, you might need to write code like this:
gapminder <- read_csv("/Users/njtierney/Desktop/rmd4sci-materials/data/gapminder.csv")

This is a problem, because this is not portable code.

10 / 69
  • To read in the gapminder.csv file, you might need to write code like this:
gapminder <- read_csv("/Users/njtierney/Desktop/rmd4sci-materials/data/gapminder.csv")

This is a problem, because this is not portable code.

It has ZERO chance of working on someone else's machine

10 / 69

If you have an RStudio project file inside the rmd4sci-materials folder, you can instead write the following:

gapminder <- read_csv("data/gapminder.csv")
11 / 69

Your Turn

  • What folders are above the health.csv file in the following given file path?

"/Users/miles/etc1010/week1/data/health.csv"

  • What would be the result of using the following code in demo-gapminder.Rmd, and then using the code, and then moving this to another location, say inside your C drive?
setwd("Downloads/etc1010/week1/week1.Rmd)
12 / 69

Is there an answer to the madness?

  • This file path situation is a real pain.
13 / 69

Is there an answer to the madness?

  • This file path situation is a real pain.

Yes!

When you start on a new idea, new research project, paper... Anything new. It should start its life as an rstudio project.

13 / 69

One more time: say it with me

When you start on a new idea, new research project, paper... Anything new. It should start its life as an rstudio project.

14 / 69

Demo

15 / 69

Rstudio projects help keep related work together in the same place.

  • Keep all your files together
  • Set the working directory to the project directory
  • Starts a new session of R
  • Restore previously edited files into the editor tabs
  • Restore other rstudio settings
  • Allow for multiple R projects open at the same time.
16 / 69

Rstudio projects help keep you sane, because:

  • Projects are independent.
  • You can work on different projects at the same time.
  • Objects & functions created in one project won't impact another.
  • You can refer to your data and other projects in a consistent way.
17 / 69

Rstudio projects help keep you sane, because:

And finally, the big one

RStudio projects help resolve file path problems, because they automatically set the working directory to the location of the rstudio project.

18 / 69

A Bit more on file paths

19 / 69

The "here" package

  • RStudio projects help resolve file path problems
  • In some cases you might have many folders in your r project. To help navigate them appropriately, you can use the here package to provide the full path directory, in a compact way.
here::here("exercise")
## [1] "/Users/ntie0001/github/njtierney/Data_Modelling_and_Computing/static/lectures/exercise"
20 / 69

The here package

here::here("exercise", "lecture-6b-exercise.Rmd")
## [1] "/Users/ntie0001/github/njtierney/Data_Modelling_and_Computing/static/lectures/exercise/lecture-6b-exercise.Rmd"
21 / 69
here::here("exercise", "lecture-6b-exercise.Rmd")

You can read the above here code as:

In the folder exercise, there is a file called lecture-6b-exercise.Rmd. Can you please give me the full path to that file?

22 / 69

The here package

This is really handy for a few reasons:

  1. It makes file paths completely portable
  2. Rmarkdown documents have a special way of looking for files, this helps eliminate file path pain.
  3. If you decide to not use RStudio projects, you have code that will work on any machine
23 / 69

Remember

If the first line of your R script is

setwd("C:\Users\jenny\path\that\only\I\have")

I will come into your office and SET YOUR COMPUTER ON FIRE 🔥.

-- Jenny Bryan

24 / 69

Aside: How to create an RStudio project

25 / 69

Summary of file paths and rstudio projects

So far we have:

  • Learnt what file paths are
  • How to setup an rstudio project
  • How to construct full file paths with the here package
26 / 69

Go to ed and finish quiz 6b

27 / 69

Motivating Functions

28 / 69

Remember web scraping?

29 / 69

How many episodes are there of Stranger Things?

st_episode <-
bow("https://www.imdb.com/title/tt4574334/") %>%
scrape() %>%
html_nodes(".np_right_arrow .bp_sub_heading") %>%
html_text() %>%
str_remove(" episodes") %>%
as.numeric()
st_episode
## [1] 25
30 / 69

How many episodes of stranger things? And ... Mindhunter?

st_episode <- bow("https://www.imdb.com/title/tt4574334/") %>%
scrape() %>%
html_nodes(".np_right_arrow .bp_sub_heading") %>%
html_text() %>%
str_remove(" episodes") %>%
as.numeric()
st_episode
## [1] 25
mh_episodes <- bow("https://www.imdb.com/title/tt4574334/") %>%
scrape() %>%
html_nodes(".np_right_arrow .bp_sub_heading") %>%
html_text() %>%
str_remove(" episodes") %>%
as.numeric()
mh_episodes
## [1] 25
31 / 69

Why functions?

  • Automate common tasks in a power powerful and general way than copy-and-pasting:
    • Give a functions an evocative name that makes code easier to understand.
    • As requirements change, you only need to update code in one place, instead of many.
    • You eliminate the chance of making incidental mistakes when you copy and paste (i.e. updating a variable name in one place, but not in another).
32 / 69

Why functions?

  • Down the line: Improve your reach as a data scientist by writing functions (and packages!) that others use
33 / 69

Setup

library(tidyverse)
library(rvest)
library(polite)
st <- bow("http://www.imdb.com/title/tt4574334/") %>% scrape()
twd <- bow("http://www.imdb.com/title/tt1520211/") %>% scrape()
got <- bow("http://www.imdb.com/title/tt0944947/") %>% scrape()
34 / 69

When should you write a function?

Whenever you’ve copied and pasted a block of code more than twice.

When you want to clearly express some set of actions

(there are many other reasons as well!)

35 / 69

Do you see any problems in the code below?

st_episode <- st %>%
html_nodes(".np_right_arrow .bp_sub_heading") %>%
html_text() %>%
str_replace(" episodes", "") %>%
as.numeric()
got_episode <- got %>%
html_nodes(".np_right_arrow .bp_sub_heading") %>%
html_text() %>%
str_replace(" episodes", "") %>%
as.numeric()
twd_episode <- got %>%
html_nodes(".np_right_arrow .bp_sub_heading") %>%
html_text() %>%
str_replace(" episodes", "") %>%
as.numeric()
36 / 69

Inputs

How many inputs does the following code have?

st_episode <- st %>%
html_nodes(".np_right_arrow .bp_sub_heading") %>%
html_text() %>%
str_replace(" episodes", "") %>%
as.numeric()
37 / 69

Turn the code into a function

Pick a short but informative name, preferably a verb.





scrape_episode <-
38 / 69

Turn your code into a function

  • Pick a short but informative name, preferably a verb.
  • List inputs, or arguments, to the function inside function. If we had more the call would look like function(x, y, z).


scrape_episode <- function(x){
}
39 / 69

Turn your code into a function

  • Pick a short but informative name, preferably a verb.
  • List inputs, or arguments, to the function inside function. If we had more the call would look like function(x, y, z).
  • Place the code you have developed in body of the function, a { block that immediately follows function(...).
scrape_episode <- function(x){
x %>%
html_nodes(".np_right_arrow .bp_sub_heading") %>%
html_text() %>%
str_replace(" episodes", "") %>%
as.numeric()
}
40 / 69

Turn your code into a function

scrape_episode <- function(x){
x %>%
html_nodes(".np_right_arrow .bp_sub_heading") %>%
html_text() %>%
str_replace(" episodes", "") %>%
as.numeric()
}
scrape_episode(st)
## [1] 25
41 / 69

Check your function

  • Number of episodes in The Walking Dead
scrape_episode(twd)
## [1] 147
  • Number of episodes in Game of Thrones
scrape_episode(got)
## [1] 73
42 / 69

Naming functions (it's hard)

"There are only two hard things in Computer Science: cache invalidation and naming things." - Phil Karlton

43 / 69

Naming functions (it's hard)

  • Names should be short but clearly evoke what the function does
44 / 69

Naming functions (it's hard)

  • Names should be short but clearly evoke what the function does
  • Names should be verbs, not nouns
44 / 69

Naming functions (it's hard)

  • Names should be short but clearly evoke what the function does
  • Names should be verbs, not nouns
  • Multi-word names should be separated by underscores (snake_case as opposed to camelCase)
44 / 69

Naming functions (it's hard!)

  • A family of functions should be named similarly (scrape_title, scrape_episode, scrape_genre, etc.)
45 / 69

Naming functions (it's hard!)

  • A family of functions should be named similarly (scrape_title, scrape_episode, scrape_genre, etc.)
  • Avoid overwriting existing (especially widely used) functions (e.g., ggplot)
45 / 69

Scraping show info

scrape_show_info <- function(x){
title <- x %>%
html_node("#title-overview-widget h1") %>%
html_text() %>%
str_trim()
runtime <- x %>%
html_node("time") %>%
html_text() %>%
str_replace("\\n", "") %>%
str_trim()
genres <- x %>%
html_nodes(".txt-block~ .canwrap a") %>%
html_text() %>%
str_trim() %>%
paste(collapse = ", ")
tibble(title = title, runtime = runtime, genres = genres)
}
46 / 69
scrape_show_info(st)
## # A tibble: 1 x 3
## title runtime genres
## <chr> <chr> <chr>
## 1 Stranger Things 51min Drama, Fantasy, Horror, Mystery, Sci-Fi, Thriller
scrape_show_info(twd)
## # A tibble: 1 x 3
## title runtime genres
## <chr> <chr> <chr>
## 1 The Walking Dead 44min Drama, Horror, Thriller
47 / 69

How to update this function to use page URL as argument?

scrape_show_info <- function(x){
title <- x %>%
html_node("#title-overview-widget h1") %>%
html_text() %>%
str_trim()
runtime <- x %>%
html_node("time") %>%
html_text() %>%
str_replace("\\n", "") %>%
str_trim()
genres <- x %>%
html_nodes(".txt-block~ .canwrap a") %>%
html_text() %>%
str_trim() %>%
paste(collapse = ", ")
tibble(title = title, runtime = runtime, genres = genres)
}
48 / 69
scrape_show_info <- function(x){
y <- bow(x) %>% scrape()
title <- y %>%
html_node("#title-overview-widget h1") %>%
html_text() %>%
str_trim()
runtime <- y %>%
html_node("time") %>%
html_text() %>%
str_replace("\\n", "") %>%
str_trim()
genres <- y %>%
html_nodes(".txt-block~ .canwrap a") %>%
html_text() %>%
str_trim() %>%
paste(collapse = ", ")
tibble(title = title, runtime = runtime, genres = genres)
}
49 / 69

Let's check

st_url <- "http://www.imdb.com/title/tt4574334/"
twd_url <- "http://www.imdb.com/title/tt1520211/"
50 / 69

Let's check

st_url <- "http://www.imdb.com/title/tt4574334/"
twd_url <- "http://www.imdb.com/title/tt1520211/"
scrape_show_info(st_url)
## # A tibble: 1 x 3
## title runtime genres
## <chr> <chr> <chr>
## 1 Stranger Things 51min Drama, Fantasy, Horror, Mystery, Sci-Fi, Thriller
scrape_show_info(twd_url)
## # A tibble: 1 x 3
## title runtime genres
## <chr> <chr> <chr>
## 1 The Walking Dead 44min Drama, Horror, Thriller
50 / 69

Automation

51 / 69
  • You now have a function that will scrape the relevant info on shows given its URL.
  • Where can we get a list of URLs of top 100 most popular TV shows on IMDB?
  • Write the code for doing this in your teams.
52 / 69
urls <- bow("http://www.imdb.com/chart/tvmeter") %>%
scrape() %>%
html_nodes(".titleColumn a") %>%
html_attr("href") %>%
paste("http://www.imdb.com", ., sep = "")
## [1] "http://www.imdb.com/title/tt1837492/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_1"
## [2] "http://www.imdb.com/title/tt5290382/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_2"
## [3] "http://www.imdb.com/title/tt2442560/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_3"
## [4] "http://www.imdb.com/title/tt8111088/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_4"
## [5] "http://www.imdb.com/title/tt1190634/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_5"
## [6] "http://www.imdb.com/title/tt0489974/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_6"
## [7] "http://www.imdb.com/title/tt6905542/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_7"
## [8] "http://www.imdb.com/title/tt4574334/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_8"
## [9] "http://www.imdb.com/title/tt8634332/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_9"
## [10] "http://www.imdb.com/title/tt0903747/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_10"
## [11] "http://www.imdb.com/title/tt0944947/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_11"
## [12] "http://www.imdb.com/title/tt5834204/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_12"
## [13] "http://www.imdb.com/title/tt6468322/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_13"
## [14] "http://www.imdb.com/title/tt4236770/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_14"
## [15] "http://www.imdb.com/title/tt8772296/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_15"
## [16] "http://www.imdb.com/title/tt3281796/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_16"
## [17] "http://www.imdb.com/title/tt2372162/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_17"
## [18] "http://www.imdb.com/title/tt1632701/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_18"
## [19] "http://www.imdb.com/title/tt2085059/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_19"
## [20] "http://www.imdb.com/title/tt7660850/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_20"
## [21] "http://www.imdb.com/title/tt2661044/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_21"
## [22] "http://www.imdb.com/title/tt0386676/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_22"
## [23] "http://www.imdb.com/title/tt0108778/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_23"
## [24] "http://www.imdb.com/title/tt6077448/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_24"
## [25] "http://www.imdb.com/title/tt1844624/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_25"
## [26] "http://www.imdb.com/title/tt8285216/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_26"
## [27] "http://www.imdb.com/title/tt7366338/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_27"
## [28] "http://www.imdb.com/title/tt5770786/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_28"
## [29] "http://www.imdb.com/title/tt1520211/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_29"
## [30] "http://www.imdb.com/title/tt4052886/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_30"
## [31] "http://www.imdb.com/title/tt9174582/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_31"
## [32] "http://www.imdb.com/title/tt0460681/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_32"
## [33] "http://www.imdb.com/title/tt3006802/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_33"
## [34] "http://www.imdb.com/title/tt5753856/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_34"
## [35] "http://www.imdb.com/title/tt0412253/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_35"
## [36] "http://www.imdb.com/title/tt2699110/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_36"
## [37] "http://www.imdb.com/title/tt2306299/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_37"
## [38] "http://www.imdb.com/title/tt0413573/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_38"
## [39] "http://www.imdb.com/title/tt6048596/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_39"
## [40] "http://www.imdb.com/title/tt0898266/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_40"
## [41] "http://www.imdb.com/title/tt1043813/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_41"
## [42] "http://www.imdb.com/title/tt8652642/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_42"
## [43] "http://www.imdb.com/title/tt2467372/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_43"
## [44] "http://www.imdb.com/title/tt8369840/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_44"
## [45] "http://www.imdb.com/title/tt6398232/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_45"
## [46] "http://www.imdb.com/title/tt8179162/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_46"
## [47] "http://www.imdb.com/title/tt0452046/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_47"
## [48] "http://www.imdb.com/title/tt8685324/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_48"
## [49] "http://www.imdb.com/title/tt3032476/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_49"
## [50] "http://www.imdb.com/title/tt2708480/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_50"
## [51] "http://www.imdb.com/title/tt2891574/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_51"
## [52] "http://www.imdb.com/title/tt4955642/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_52"
## [53] "http://www.imdb.com/title/tt1606375/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_53"
## [54] "http://www.imdb.com/title/tt1327801/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_54"
## [55] "http://www.imdb.com/title/tt3920596/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_55"
## [56] "http://www.imdb.com/title/tt0364845/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_56"
## [57] "http://www.imdb.com/title/tt5057054/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_57"
## [58] "http://www.imdb.com/title/tt5016504/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_58"
## [59] "http://www.imdb.com/title/tt5574490/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_59"
## [60] "http://www.imdb.com/title/tt0475784/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_60"
## [61] "http://www.imdb.com/title/tt0203259/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_61"
## [62] "http://www.imdb.com/title/tt2741602/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_62"
## [63] "http://www.imdb.com/title/tt4158110/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_63"
## [64] "http://www.imdb.com/title/tt2356777/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_64"
## [65] "http://www.imdb.com/title/tt3566726/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_65"
## [66] "http://www.imdb.com/title/tt0118401/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_66"
## [67] "http://www.imdb.com/title/tt5296406/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_67"
## [68] "http://www.imdb.com/title/tt0098749/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_68"
## [69] "http://www.imdb.com/title/tt3743822/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_69"
## [70] "http://www.imdb.com/title/tt3636060/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_70"
## [71] "http://www.imdb.com/title/tt8022928/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_71"
## [72] "http://www.imdb.com/title/tt0141842/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_72"
## [73] "http://www.imdb.com/title/tt5420376/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_73"
## [74] "http://www.imdb.com/title/tt4124758/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_74"
## [75] "http://www.imdb.com/title/tt2364582/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_75"
## [76] "http://www.imdb.com/title/tt2193021/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_76"
## [77] "http://www.imdb.com/title/tt9208876/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_77"
## [78] "http://www.imdb.com/title/tt1586680/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_78"
## [79] "http://www.imdb.com/title/tt0472954/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_79"
## [80] "http://www.imdb.com/title/tt0804503/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_80"
## [81] "http://www.imdb.com/title/tt6143796/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_81"
## [82] "http://www.imdb.com/title/tt0460649/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_82"
## [83] "http://www.imdb.com/title/tt1064899/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_83"
## [84] "http://www.imdb.com/title/tt0436992/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_84"
## [85] "http://www.imdb.com/title/tt7671068/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_85"
## [86] "http://www.imdb.com/title/tt2802850/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_86"
## [87] "http://www.imdb.com/title/tt3526078/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_87"
## [88] "http://www.imdb.com/title/tt3107288/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_88"
## [89] "http://www.imdb.com/title/tt1266020/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_89"
## [90] "http://www.imdb.com/title/tt0412142/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_90"
## [91] "http://www.imdb.com/title/tt5071412/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_91"
## [92] "http://www.imdb.com/title/tt1124373/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_92"
## [93] "http://www.imdb.com/title/tt8425532/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_93"
## [94] "http://www.imdb.com/title/tt5180504/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_94"
## [95] "http://www.imdb.com/title/tt2861424/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_95"
## [96] "http://www.imdb.com/title/tt4786824/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_96"
## [97] "http://www.imdb.com/title/tt1796960/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_97"
## [98] "http://www.imdb.com/title/tt3230854/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_98"
## [99] "http://www.imdb.com/title/tt9054904/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_99"
## [100] "http://www.imdb.com/title/tt1869454/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=332cb927-0342-42b3-815c-f9124e84021d&pf_rd_r=MZW2CP8ZEQDRJHHGNW50&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=tvmeter&ref_=chttvm_tt_100"
53 / 69

Go to each page, scrape show info

  • Now we need a way to programatically direct R to each page on the urls list and run the scrape_show_info function on that page.
scrape_show_info(urls[1])
## # A tibble: 1 x 3
## title runtime genres
## <chr> <chr> <chr>
## 1 13 Reasons Why 1h Drama, Mystery
scrape_show_info(urls[2])
## # A tibble: 1 x 3
## title runtime genres
## <chr> <chr> <chr>
## 1 Mindhunter 1h Crime, Drama, Thriller
scrape_show_info(urls[3])
## # A tibble: 1 x 3
## title runtime genres
## <chr> <chr> <chr>
## 1 Peaky Blinders 1h Crime, Drama
54 / 69

Go to each page, scrape show info

In other words, we want to map the scrape_show_info function to each element of show_urls:

top_100_shows <- map_df(urls, scrape_show_info)
  • This will hit the urls one after another, and grab the info.
55 / 69

Passing functions to ... functions?

  • The fact that we can pass a function to another is a big idea, and is one of the things that makes R a functional programming language.
  • It's a bit mind-bending, but it's an idea worth practicing and comfortable with
56 / 69

aside: lists as an idea: first...vectors

  • c() creates a vector of one type
  • e.g., x <- c(1, 2, 3, "A") contains:
  • [1] "1" "2" "3" "A"
  • class(x) returns:
  • [1] "character"
57 / 69

aside: lists as an idea: first...vectors

  • You can look up vectors based on position with []
  • x[1] returns the first thing
  • x[2] returns the second thing
  • x[1:2] returns the first through to second thing
58 / 69

aside: lists as an idea: second...lists

  • list() creates list, which can be any type
y <- list(1,2,3,"x"); y
#> [[1]]
#> [1] 1
#>
#> [[2]]
#> [1] 2
#>
#> [[3]]
#> [1] 3
#>
#> [[4]]
#> [1] "x"
59 / 69

aside: lists as an idea: second...lists

  • You access positions of a list with [[]]
  • So y[[1]] returns: 1
60 / 69

aside: a data frame is actually a list!

61 / 69

calculate the mean for every column:

map(mtcars, mean)
## $mpg
## [1] 20.09062
##
## $cyl
## [1] 6.1875
##
## $disp
## [1] 230.7219
##
## $hp
## [1] 146.6875
##
## $drat
## [1] 3.596563
##
## $wt
## [1] 3.21725
##
## $qsec
## [1] 17.84875
##
## $vs
## [1] 0.4375
##
## $am
## [1] 0.40625
##
## $gear
## [1] 3.6875
##
## $carb
## [1] 2.8125
62 / 69

calculate the mean for every column:

map_dbl(mtcars, mean)
## mpg cyl disp hp drat wt qsec vs
## 20.090625 6.187500 230.721875 146.687500 3.596563 3.217250 17.848750 0.437500
## am gear carb
## 0.406250 3.687500 2.812500
63 / 69

Range for every column: writing a function

my_range <- function(x){
max(x) - min(x)
}
map_dbl(mtcars, my_range)
## mpg cyl disp hp drat wt qsec vs am gear carb
## 23.500 4.000 400.900 283.000 2.170 3.911 8.400 1.000 1.000 2.000 7.000
64 / 69

Range for every column: writing a function in map

map_dbl(mtcars, .f = function(x) max(x) - min(x))
## mpg cyl disp hp drat wt qsec vs am gear carb
## 23.500 4.000 400.900 283.000 2.170 3.911 8.400 1.000 1.000 2.000 7.000
65 / 69

Range for every column: writing a function in map

map_dbl(mtcars, .f = ~(max(.) - min(.)))
## mpg cyl disp hp drat wt qsec vs am gear carb
## 23.500 4.000 400.900 283.000 2.170 3.911 8.400 1.000 1.000 2.000 7.000
66 / 69

Your Turn: rstudio.cloud

Take the lab quiz!

67 / 69

Resources

68 / 69

Share and share alike

Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.

69 / 69

Recap

  • style (it's important!)
  • ed quiz
2 / 69
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow