Assignment Summary

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.

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 (e.g. “books.html”, “books.xml”, and “books.json”). To help you better understand the different file structures, I’d prefer that you create each of these files “by hand” unless you’re already very comfortable with the file formats.

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?

Your deliverable is the three source files and the R code. If you can, package your assignment solution up into an .Rmd file and publish to rpubs.com. [This will also require finding a way to make your three text files accessible from the web].

Load books data from an HTML file

library(textreadr)
library(rvest)
library(dplyr)
html_data <- as.data.frame(read_html("https://raw.githubusercontent.com/krpopkin/DATA607-Class-Repository/master/Week_7/html/books_for_assignment5.html") %>% html_table(fill=TRUE))
htmldf <- html_data %>% `colnames<-`(c('row', 'title', 'author', 'publisher', 'year', 'amazon_rank'))
htmldf <- select(htmldf, title, author, publisher, year, amazon_rank)
htmldf
##               title                       author                publisher year
## 1 When to Walk Away                  Gary Thomas                Zondervan 2019
## 2         Humilitas                 John Dickson                Zondervan 2011
## 3       Left Behind Tim Lahaye and Jerry Jenkins Tyndale House Publishers 1995
##   amazon_rank
## 1        4936
## 2      191819
## 3       75775

Load books data from an XML file

library(XML)
xml_data <- read_xml("https://raw.githubusercontent.com/krpopkin/DATA607-Class-Repository/master/Week_7/xml/books_for_assignment5.xml")

xml_data_result <- xmlParse(xml_data)

xmldf <- xmlToDataFrame(xml_data_result)
xmldf <- xmldf %>% `colnames<-`(c('title', 'author', 'publisher', 'year', 'amazon_rank'))
xmldf
##               title                       author                publisher year
## 1 When to Walk Away                  Gary Thomas                Zondervan 2019
## 2         Humilitas                 John Dickson                Zondervan 2011
## 3       Left Behind Tim Lahaye and Jerry Jenkins Tyndale House Publishers 1995
##   amazon_rank
## 1        4936
## 2      191819
## 3       75775

#Load books data from a JSON file

library(rjson)
json_data <- fromJSON(file = "https://raw.githubusercontent.com/krpopkin/DATA607-Class-Repository/master/Week_7/json/books_for_assignment5.json")
jsondf <- as.data.frame(json_data)
jsondf <- jsondf %>% `colnames<-`(c('title', 'author', 'publisher', 'year', 'amazon_rank'))
jsondf
##               title                       author                publisher year
## 1 When to Walk Away                  Gary Thomas                Zondervan 2019
## 2         Humilitas                 John Dickson                Zondervan 2011
## 3       Left Behind Tim Lahaye and Jerry Jenkins Tyndale House Publishers 1995
##   amazon_rank
## 1        4936
## 2      191819
## 3       75775

Summary

The three dataframes are identical after some mild tidying of the dataframes. I had to assign common column names and for the html file had to drop an index column.