Instructions

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 Libraries

  library(XML)
  library(DT)
  library(jsonlite)

HTML

Code:

Books in HTML
<th>Title</th>
<th>Author</th>
<th>ISBN-13</th>
<th>Edition Number</th>
<th>Pages</th>
<td>C++ Without Fear : A Beginner's Guide That Makes You Feel Smart Author</td>
<td>Brian Overland</td>
<td>978-0132673266</td>
<td>2</td>
<td>595</td>
<td>Organic Chemistry</td>
<td>Marc Loudon, Jim Parise</td>
<td>978-1936221349</td>
<td>6</td>
<td>1648</td>
<td>Kuby Immunology</td>
<td>Jenni Punt, Sharon A. Stranford, Patricia P. Jones, Judith A. Owen</td>
<td>978-1464189784</td>
<td>8</td>
<td>944</td>

Below is the dataframe we extracted from the HTML:

  booksHTML <- htmlParse(file = "books.html")
  booksHTML <- readHTMLTable(booksHTML, stringAsFactors=FALSE)
  booksHTML <- booksHTML[[1]]
  datatable(booksHTML)

XML

Code:

<pre><code>C++ Without Fear : A Beginner's Guide That Makes You Feel Smart Author</code></pre> Brian Overland 978-0132673266 2 595 <pre><code>Organic Chemistry</code></pre> Marc Loudon, Jim Parise 978-1936221349 6 1648 <pre><code>Kuby Immunology</code></pre>

Jenni Punt, Sharon A. Stranford, Patricia P. Jones, Judith A. Owen 978-1464189784 8 944
Below is the dataframe we extracted from the XML:

  booksXML <- xmlParse(file="books.XML")
  booksXML <- xmlToDataFrame(booksXML, stringsAsFactors = FALSE)
  datatable(booksXML)

JSON

Code

{ “books”: [
{
“title”: “C++ Without Fear : A Beginner’s Guide That Makes You Feel Smart Author”,
“author”: “Brian Overland”,
“isbn13”: “978-0132673266”,
“edition”: “2”,
“pages”: “595”
},
{
“title”: “Organic Chemistry”,
“author”: “Marc Loudon, Jim Parise”,
“isbn13”: “978-1936221349”,
“edition”: “6”,
“pages”: “1648”
},
{
“title”: “Kuby Immunology”,
“author”: “Jenni Punt, Sharon A. Stranford, Patricia P. Jones, Judith A. Owen”,
“isbn13”: “978-1464189784”,
“edition”: “8”,
“pages”: “944”
}
]
}
JSON code:

  booksJSON <- fromJSON("books.JSON") %>% as.data.frame
  datatable(booksJSON)

Conclusion

All data frames generated from HTML, XML, and JSON file formats are identical.