Overview

  1. Pick three of your favorite books on one of your favorite subjects. At least one of the books should have more than one author. For each book, include the title, authors, and two or three other attributes that you find interesting.

  2. Take the information that you’ve selected about these three books, and separately create three files which store the book’s information in HTML (using an html table), XML, and JSON formats

  3. Write R code, using your packages of choice, to load the information from each of the three sources into separate R data frames. Are the three data frames identical?

1. Books

Book 1: Title: Statistics: Unlocking the Power of Data Authors: Robin H. Lock, Patti Frazer Lock, Kari Lock Morgan, Eric F. Lock, Dennis F. Lock Attribute 1: 3rd Edition Attribute 2: 864 pages Book 2: Title: R for Data Science Authors: Hadley Wickham, Mine Çetinkaya-Rundel, Garrett Grolemund Attribute 1: 2nd Edition Attribute 2: Online Book 3: Title: OpenIntro Statistics Authors: David Diez, Mine Çetinkaya-Rundel, Christopher D Barr Attribute 1: 4th Edition Attribute 2: pdf

2a. HTML

#bookhtml <- read_html("bookHTMl.html")
my_df <- as.data.frame(read_html("bookHTMl.html") %>% html_table(fill=TRUE))
tibble(my_df)
## # A tibble: 3 × 4
##   Title                                   Authors                 Edition Format
##   <chr>                                   <chr>                   <chr>   <chr> 
## 1 Statistics: Unlocking the Power of Data "Robin H. Lock, Patti … 3rd Ed… Hardc…
## 2 R for Data Science                      "Hadley Wickham, Mine … 2nd Ed… Websi…
## 3 OpenIntro Statistics                    "David Diez, Mine Ã\u0… 4th Ed… PDF

2b. XML

bookxml <- read_xml("bookXML.xml")  
Title <- xml_text(xml_find_all(bookxml, xpath = "//Title"))
Authors <- xml_text(xml_find_all(bookxml, xpath = "//Authors"))
Edition <- xml_text(xml_find_all(bookxml, xpath = "//Edition"))
Format <- xml_text(xml_find_all(bookxml, xpath = "//Format"))
xmldf <- tibble(Title, Authors, Edition, Format)
tibble(xmldf)
## # A tibble: 3 × 4
##   Title                                   Authors                 Edition Format
##   <chr>                                   <chr>                   <chr>   <chr> 
## 1 Statistics: Unlocking the Power of Data Robin H. Lock, Patti F… 3rd     Hardc…
## 2 R for Data Science                      Hadley Wickham, Mine Ç… 2nd     Websi…
## 3 OpenIntro Statistics                    David Diez, Mine Çetin… 4th     PDF

2c. JSON

bookJSON <- fromJSON("bookJSON.json")
jsondf <- as.data.frame(bookJSON)
tibble(jsondf)
## # A tibble: 3 × 4
##   Title                                   Authors                 Edition Format
##   <chr>                                   <chr>                   <chr>   <chr> 
## 1 Statistics: Unlocking the Power of Data Robin H. Lock, Patti F… 3rd Ed… Hardc…
## 2 R for Data Science                      Hadley Wickham, Mine Ç… 2nd Ed… Websi…
## 3 OpenIntro Statistics                    David Diez, Mine Çetin… 4th Ed… PDF