Consider this simple example
library(rvest)
library(tidyverse)
library(dplyr)
library(lubridate)
library(tibble)
mytib <- tibble(mylink = c('https://en.wikipedia.org/wiki/List_of_software_bugs',
'https://en.wikipedia.org/wiki/Software_bug'))
mytib <- mytib %>% mutate(html.data = map(mylink, ~read_html(.x)))
> mytib
# A tibble: 2 x 2
mylink html.data
<chr> <list>
1 https://en.wikipedia.org/wiki/List_of_software_bugs <xml_dcmn>
2 https://en.wikipedia.org/wiki/Software_bug <xml_dcmn>
> mytib$html.data[1]
[[1]]
{html_document}
<html class="client-nojs" lang="en" dir="ltr">
[1] <head>\n<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">\n<meta charset="UTF-8">\n<title> ...
[2] <body class="mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject mw-editable page-List_of_software_b ...
As you can see, my tibble
correctly contains the html code of the two different wikipedia pages stored in the column mylink
. The problem is that I am not able to store this hard-worked scraping to disk. A simple read_csv
will fail
> mytib %>% write_csv('mydata.csv')
Error in stream_delim_(df, path, ..., bom = bom, quote_escape = quote_escape) :
Don't know how to handle vector of type list.
while write to rds
will not work correctly
mytib %>% write_rds('mydata.rds')
test <- read_rds('mydata.rds')
test$html.data[1]
> test$html.data[1]
[[1]]
Error in doc_type(x) : external pointer is not valid
What should I do? In which format should I store my data? Thanks!