I previously studied history and have many books in my collection from that time (and my own personal interest before and after). I selected three books about World War I to be the topic of my assignment. I documented each book’s title, authors, publication year, publisher, and ISBN in a hand written .json and .html file. Then, I used R to read the contents into a dataframe and compared the results.
Data Import
Using the rvest package, I’m able to read in the html file as tables. The first table contains my book data and the second contains table attributes. For our purposes, we just need the first table, so I extract that into a data frame.
Code
html_url <-"https://raw.githubusercontent.com/jocslater-code/DATA607/refs/heads/main/Week7/book.html"# Read in as tablehtml_tbl <-read_html(html_url) %>%html_table()# Extract first table into dataframehtml_df <- html_tbl[[1]]print(html_df)
Using the jsonlite package, I read in the json file directly into a dataframe.
Code
json_url <-"https://raw.githubusercontent.com/jocslater-code/DATA607/refs/heads/main/Week7/books.json"# Load json into data framejson_df <-fromJSON(json_url)# View the dataframeprint(json_df)
title
1 A Peace to End All Peace
2 The Sleepwalkers: How Europe Went to War in 1914
3 14-18: Understanding the Great War
authors publication_year publisher
1 David Fromkin 1989 Henry Holt and Co.
2 Christopher Clark 2012 HarperCollins
3 Stéphane Audoin-Rouzeau, Annette Becker 2002 Hill and Wang
isbn
1 978-0805068849
2 978-0061146657
3 978-0809046430
Each format handles the multiple authors differently. The json format casts authors as a list, so that the books with multiple authors just has a list of two elements. The html format concatonates the authors together, separated by a comma.
Next Steps
The special character issues are due to R using my system default encoding, rather than UTF-8. This can cause an misinterpertation of multi-byte characters like é. If I wanted to resolve this, I would be explicit about the system encoding.