Here is the code for creating a data.frame for my books from an HTML doctype.
library(XML)
## Warning: package 'XML' was built under R version 3.2.4
#Please create your own folder path here
booksHTML_parse <- htmlParse(file = "/Users/digitalmarketer1977/Desktop/Fav Books.html" )
(booksHTML <- readHTMLTable(booksHTML_parse, header = TRUE, skip.rows = integer(), trim = TRUE, elFun = xmlValue, as.data.frame = TRUE))
## $`NULL`
## Title Author Genre Type
## 1 Wretched of the Earth Frantz Fanon African Politics
## 2 The New Jim Crow Michelle Alexander African-American Politics
## 3 American Negro Slavery Allen Weinstein American History
## 4 American Negro Slavery Frank Otto Gatell American History
## Language
## 1 French
## 2 English
## 3 English
## 4 English
#Not clear on why a null value is thrown here, or why two lists are created.
Here is the code for creating a data.frame for my books from an XML doc.
library(XML)
library(xtable)
## Warning: package 'xtable' was built under R version 3.2.3
#Please create your own folder path here
booksXML_parse <- xmlParse(file = "/Users/digitalmarketer1977/Desktop/My Fav Books.xml")
#The validation check failes on this file, but it doesn't seem to matter. Data Frame prints as expected.
(booksXML <- xmlToDataFrame(booksXML_parse))
## title author genre type
## 1 The Wretched of the Earth Frantz Fanon African Politics
## 2 The New Jim Crow Michelle Alexander African-American Politics
## 3 American Negro Slavery Allen Weinstein American History
## 4 American Negro Slavery James Otto Gatto American History
## language
## 1 French
## 2 English
## 3 English
## 4 English
Here is the code for creating a data.frame for my books from an JSON file.
library(XML)
require(jsonlite)
## Loading required package: jsonlite
require(RJSONIO)
## Loading required package: RJSONIO
##
## Attaching package: 'RJSONIO'
##
## The following objects are masked from 'package:jsonlite':
##
## fromJSON, toJSON
#checks to see if JSON file is valid
isValidJSON("/Users/digitalmarketer1977/Desktop/favbooks.json")
## [1] TRUE
#Please create your own folder path here
booksJSON<- fromJSON("/Users/digitalmarketer1977/Desktop/favbooks.json", nullValue = NA, simplify = FALSE)
(booksJSONdf <-do.call("rbind", lapply (booksJSON, data.frame, stringsAsFactors = TRUE)))
## title author genre type
## 1 The Wretched of the Earth Frantz Fanon African Politics
## 2 The New Jim Crow Michelle Alexander African-American Politics
## 3 American Negro Slavery Allen Weinstein American History
## 4 American Negro Slavery James Otto Gatell American History
## language
## 1 French
## 2 English
## 3 English
## 4 English