Question

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 needed libraries

library(knitr)
library(XML)
library(httr)
library(rjson)
library(RCurl)
## Loading required package: bitops

HTML File

html_url<-readHTMLTable(getURL("https://raw.githubusercontent.com/juanellemarks/JuanelleMarks_DATA607_2018/master/favourite_books.html"))
html_url<-lapply(html_url[[1]], function(x) {unlist(x)})
df.html<-as.data.frame(html_url)
#df.html
kable(df.html)
X.Title. X.Authors. X.Date.of.Publication X.Genre.
A Smarter Way To Learn Python Mark Meyers 2017 Non Fiction
Python and Algorithmic Thinking For the Complete Beginner Aritides Bouras and Loukia Ainarozidou 2015 Non Fiction
Learn Python in One Day and Learn it Well Jamie Chan 2017 Non Fiction

Json File

json_url<-fromJSON(file = "https://raw.githubusercontent.com/juanellemarks/JuanelleMarks_DATA607_2018/master/Books.json")
json_url<-lapply(json_url[[1]], function(x) {unlist(x)})
#df.json<-as.data.frame(json_url)
df.json<-as.data.frame(do.call("rbind", json_url))
#df.json<-as.data.frame(json_url)
kable(df.json)
Title Author Year Genre
A Smarter Way to Learn Python Mark Meyers 2017 Non Fiction
Python and Algorithmic Thinking for the Complete Beginner Aristides Bouras, Loukia Ainorozidou 2015 Non Fiction
Learn Python in One Day and Learn it Well Jamie Chan 2017 Non Fiction

XML File

xml_url<-xmlInternalTreeParse(getURL("https://raw.githubusercontent.com/juanellemarks/JuanelleMarks_DATA607_2018/master/Books5.xml"))
xml_apply<-xmlSApply(xmlRoot(xml_url), function(x) xmlSApply(x, xmlValue))
df.xml<-data.frame(t(xml_apply), row.names = NULL)
kable(df.xml)
title author year genre
A Smarter Way to Learn Python Mark Meyers 2017 Non-Fiction
Python and Algorithmic Thinking for the Complete Beginner Aristides Bouras, Loukia Ainorozidou 2015 Non-Fiction
Learn Python in One Day and Learn it Well Jamie Chan 2017 Non-Fiction

Conclusion

The rendering of the three files is somewhat identical. However, the approach to having these files rendered in a readable format varies.