{"id":14068930,"url":"https://github.com/mkearney/readthat","last_synced_at":"2025-04-12T10:50:55.220Z","repository":{"id":56936739,"uuid":"209839948","full_name":"mkearney/readthat","owner":"mkearney","description":"Read Text Data","archived":false,"fork":false,"pushed_at":"2019-10-25T16:39:54.000Z","size":1571,"stargazers_count":26,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-26T05:41:51.446Z","etag":null,"topics":["http-get","r","r-package","read","read-file","read-url","readsource","readtextfile","rstats","text"],"latest_commit_sha":null,"homepage":null,"language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mkearney.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-20T16:55:10.000Z","updated_at":"2024-02-03T17:01:15.000Z","dependencies_parsed_at":"2022-08-21T07:20:42.471Z","dependency_job_id":null,"html_url":"https://github.com/mkearney/readthat","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkearney%2Freadthat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkearney%2Freadthat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkearney%2Freadthat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkearney%2Freadthat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mkearney","download_url":"https://codeload.github.com/mkearney/readthat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248557844,"owners_count":21124165,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http-get","r","r-package","read","read-file","read-url","readsource","readtextfile","rstats","text"],"created_at":"2024-08-13T07:06:29.359Z","updated_at":"2025-04-12T10:50:55.171Z","avatar_url":"https://github.com/mkearney.png","language":"R","readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\nlibrary(readthat)\n```\n\n# readthat \u003cimg src='man/figures/logo.png' align=\"right\" height=\"173.5\" /\u003e\n\n\u003c!-- badges: start --\u003e\n[![CRAN status](https://www.r-pkg.org/badges/version/readthat)](https://CRAN.R-project.org/package=readthat)\n[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)\n[![Travis build status](https://travis-ci.org/mkearney/readthat.svg?branch=master)](https://travis-ci.org/mkearney/readthat)\n[![Codecov test coverage](https://codecov.io/gh/mkearney/readthat/branch/master/graph/badge.svg)](https://codecov.io/gh/mkearney/readthat?branch=master)\n\u003c!-- badges: end --\u003e\n\nQuickly read text/source from local files and web pages.\n\n## Installation\n\nYou can install the development released version of readthat from Github with:\n\n``` r\nremotes::install_github(\"mkearney/readthat\")\n```\n\n## Examples\n\nLet's say we want to read-in the source of the following websites:\n\n```{r}\n## a vector of URLs\nurls \u003c- c(\n  \"https://mikewk.com\",\n  \"https://cnn.com\",\n  \"https://www.cnn.com/us\"\n)\n```\n\nUse `readthat::read()` to read the text/source of a single file/URL\n\n```{r}\n## read single web/file (returns text vector)\nx \u003c- read(urls[1])\n\n## preview output\nsubstr(x, 1, 60)\n\n## use apply functions to read multiple pages\nxx \u003c- sapply(urls, read)\n\n## preview output\nlapply(xx, substr, 1, 60)\n```\n\n## Comparisons\n\nBenchmark comparison for reading a text file:\n\n```{r}\n## save a text file\nwriteLines(read(urls[1]), x \u003c- tempfile())\n\n## coompare read times\nbm_file \u003c- bench::mark(\n  readr = readr::read_lines(x),\n  readthat = read(x),\n  readLines = readLines(x),\n  check = FALSE\n)\n\n## view results\nbm_file\n```\n\n\n```{r, include=FALSE}\np1 \u003c- ggplot2::autoplot(bm_file)\np1 + ggplot2::ggsave(\"man/figures/README-bm_file.png\",\n    width = 9, height = 5, units = \"in\")\n```\n\n\n![](man/figures/README-bm_file.png)\n\nBenchmark comparison for reading a web page:\n\n```{r}\nx \u003c- \"https://www.espn.com/nfl/scoreboard\"\nbm_html \u003c- bench::mark(\n  httr = httr::content(httr::GET(x), as = \"text\", encoding = \"UTF-8\"),\n  xml2 = xml2::read_html(x),\n  readthat = read(x),\n  readLines = readLines(x, warn = FALSE),\n  readr = readr::read_lines(x),\n  check = FALSE,\n  iterations = 25,\n  filter_gc = TRUE\n)\nbm_html\n```\n\n```{r, include=FALSE}\np2 \u003c- ggplot2::autoplot(bm_html)\np2 + ggplot2::ggsave(\"man/figures/README-bm_html.png\",\n    width = 9, height = 5, units = \"in\")\n```\n\n\n![](man/figures/README-bm_html.png)\n\n","funding_links":[],"categories":["R"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkearney%2Freadthat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmkearney%2Freadthat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkearney%2Freadthat/lists"}