My Coding > Software > R > R: HTML data

R: HTML data

Preparation R for using HTML data

R can read exel spreadsheets . To read exel files it is necessary to use function read_exel(filename)

Before this function will be available in R, it is necessary to install proper dependencies for linux:

sudo apt-get install -y libxml2-dev libcurl4-openssl-dev libssl-dev

and also install this package with the R environment


Reading HTML from WEB

it is possible to read HTML file from the WEB

html_data <- read_html("URL") # read html from WEB
extracted_tables <- html_table(html_data) # extract all tables to list
length(extracted_tables) # check number of extracted tables
df <- extracted_tables[1] # use first table
str(df) # check our data

Exporting to HTML

We will write to HTML internal dataset mtcars. To do so we need to redirect our print to a html file with function sink(), then print it and then finish this redirection

> library(xtable)

> sink("mtcars.html")
> print(xtable(mtcars), type="html")
> sink()

Published: 2021-11-11 03:57:32
Updated: 2021-11-17 01:15:06

Last 10 artitles

9 popular artitles

© 2020 -My blog about coding and further learning. This blog was writen with pure Perl and front-end output was performed with TemplateToolkit.