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].
url <- "https://raw.githubusercontent.com/kelloggjohnd/DATA607/master/books.html"
html_file <- getURL(url)
html_raw <- readHTMLTable(html_file, header=TRUE, which=1)
str(html_raw)## 'data.frame': 3 obs. of 8 variables:
## $ ID : Factor w/ 3 levels "01","02","03": 1 2 3
## $ Title : Factor w/ 3 levels "Harry Potter And The Goblet Of Fire",..: 2 1 3
## $ Author : Factor w/ 3 levels "J.K.Rowling",..: 3 1 2
## $ ISBN-13 : Factor w/ 3 levels "9780385199575",..: 1 2 3
## $ Publisher : Factor w/ 3 levels "Doubleday","Scholastic Paperbacks",..: 1 2 3
## $ Publication date: Factor w/ 3 levels "09/01/2002","1/31/2011",..: 3 1 2
## $ Pages : Factor w/ 3 levels "1152","74","752": 1 3 2
## $ Related Subject : Factor w/ 3 levels "Fantasy, High Fantasy, military fiction",..: 3 2 1
url <- "https://raw.githubusercontent.com/kelloggjohnd/DATA607/master/books.json"
json_raw <- fromJSON(url)
str(json_raw)## List of 1
## $ book-table:List of 1
## ..$ book:'data.frame': 3 obs. of 8 variables:
## .. ..$ ID : chr [1:3] "01" "02" "03"
## .. ..$ Title : chr [1:3] "The Stand" "Harry Potter And The Goblet Of Fire" "Towers of Midnight"
## .. ..$ Author : chr [1:3] "Stephen King" "J.K.Rowling" "Robert Jordan, Brandon Sanderson"
## .. ..$ ISBN-13 : chr [1:3] "9780385199575" "9780439139601" "9780765364876"
## .. ..$ Publisher : chr [1:3] "Doubleday" "Scholastic Paperbacks" "Tor Books"
## .. ..$ Publication date: chr [1:3] "5/01/1990" "09/01/2002" "1/31/2011"
## .. ..$ Pages : chr [1:3] "1152" "752" "1264"
## .. ..$ Related Subject : chr [1:3] "Linux" "Joomla Content Management" "Fantasy, High Fantasy, military fiction"
url <- "https://raw.githubusercontent.com/kelloggjohnd/DATA607/master/books.xml"
xml_download <- getURL(url)
xml_raw <- xmlToDataFrame(xml_download)
str(xml_raw)## 'data.frame': 3 obs. of 8 variables:
## $ ID : Factor w/ 3 levels "01","02","03": 1 2 3
## $ Title : Factor w/ 3 levels "\tTowers of Midnight",..: 3 2 1
## $ Author : Factor w/ 3 levels "J.K.Rowling",..: 3 1 2
## $ ISBN-13 : Factor w/ 3 levels "9780385199575",..: 1 2 3
## $ Publisher : Factor w/ 3 levels "Doubleday","Scholastic Paperbacks\t",..: 1 2 3
## $ Publication_date: Factor w/ 3 levels "09/01/2002","1/31/2011",..: 3 1 2
## $ Pages : Factor w/ 3 levels "1152","74","752": 1 3 2
## $ Related_Subject : Factor w/ 3 levels "Fantasy, High Fantasy, military fiction",..: 3 2 1
HTML and XML are nearly identical when processed into R. As one site (https://www.w3schools.com) and the required reading this week says in describing the difference:
* HTML is for passing the data while concerned how it looks
* XML is for passing the data while focused on what the data is.
JSON is simular to XML in:
* They are hierachical
* Can be parsed by multiple languages
However, JSON takes extra steps to get into the same format as HTML and XML. The simple export into R is a nested list which can be useful when dealing with multiple tables. The other minor difference JSON has the file formats as Characters vs Factors from the others.