Last active
October 1, 2018 08:26
-
-
Save giocomai/fce7069190fe1933c61fdabf5a5711f5 to your computer and use it in GitHub Desktop.
Convert to csv json from FactChecks and Data Commons.org
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (!require("pacman")) install.packages("pacman") | |
pacman::p_load("jsonlite") | |
pacman::p_load("tidyverse") | |
#https://www.datacommons.org/docs/download.html | |
text <- readLines(con = "fact_checks_20180502.txt") | |
text <- stringr::str_remove_all(string = text, pattern = stringr::fixed('<script type=\"application/ld+json\">')) | |
text <- stringr::str_remove_all(string = text, pattern = stringr::fixed("</script>")) | |
txtList <- purrr::map(.x = text, .f = fromJSON, simplifyDataFrame = TRUE, flatten = TRUE) | |
df <- purrr::map_df(.x = txtList, .f = as.data.frame) | |
write_csv(x = df, path = "fact_checks_20180502.csv") | |
# could perhaps be accomplished more tidily with jsonld |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment