From a16ab243e881dd9a01322d7cc4527268ededf749 Mon Sep 17 00:00:00 2001 From: Bob Rudis Date: Wed, 19 Apr 2017 10:26:32 -0400 Subject: [PATCH] readr::type_convert --- DESCRIPTION | 5 +++-- NAMESPACE | 1 + R/hgr-package.R | 4 +++- R/mercury.r | 4 +++- README.Rmd | 2 +- README.md | 6 +++--- man/hgr.Rd | 2 +- 7 files changed, 15 insertions(+), 9 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 23da876..b8194de 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -5,7 +5,7 @@ Version: 0.1.0 Date: 2017-04-19 Author: Bob Rudis (bob@rud.is) Maintainer: Bob Rudis -Description: PTools to Work with the 'Postlight' 'Mercury' 'API'. +Description: PTools to Work with the 'Postlight' 'Mercury' 'API' . URL: https://github.com/hrbrmstr/hgr BugReports: https://github.com/hrbrmstr/hgr/issues License: AGPL @@ -16,5 +16,6 @@ Depends: R (>= 3.2.0) Imports: purrr, - httr + httr, + readr RoxygenNote: 6.0.1 diff --git a/NAMESPACE b/NAMESPACE index f4424b8..0f67cc5 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -3,3 +3,4 @@ export(just_the_facts) import(httr) import(purrr) +importFrom(readr,type_convert) diff --git a/R/hgr-package.R b/R/hgr-package.R index 97b2834..74374af 100644 --- a/R/hgr-package.R +++ b/R/hgr-package.R @@ -1,10 +1,12 @@ #' Tools to Work with the 'Postlight' 'Mercury' 'API' #' -#' Mercury takes any web article and returns only the relevant content — headline, author, +#' [Mercury](https://mercury.postlight.com) takes any web article and returns only the relevant content — headline, author, #' body text, relevant images and more — free from any clutter. #' +#' @md #' @name hgr #' @docType package #' @author Bob Rudis (bob@@rud.is) #' @import purrr httr +#' @importFrom readr type_convert NULL diff --git a/R/mercury.r b/R/mercury.r index 045e1fb..3bdf5f5 100644 --- a/R/mercury.r +++ b/R/mercury.r @@ -19,7 +19,9 @@ just_the_facts <- function(url, mercury_api_key=Sys.getenv("MERCURY_API_KEY")) { res <- httr::content(res, as="text", encoding="UTF-8") res <- jsonlite::fromJSON(res, flatten=TRUE) + res <- purrr::flatten_df(res) + res <- readr::type_convert(res) - purrr::flatten_df(res) + res } \ No newline at end of file diff --git a/README.Rmd b/README.Rmd index 8817c10..0081222 100644 --- a/README.Rmd +++ b/README.Rmd @@ -4,7 +4,7 @@ output: rmarkdown::github_document `hgr` : Tools to Work with the 'Postlight' 'Mercury' 'API' -Mercury takes any web article and returns only the relevant content — headline, author, body text, relevant images and more — free from any clutter. +Mercury takes any web article and returns only the relevant content — headline, author, body text, relevant images and more — free from any clutter. You need an API key which you can get from [here](https://mercury.postlight.com). The following functions are implemented: diff --git a/README.md b/README.md index ab8cdd2..f59cb70 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ `hgr` : Tools to Work with the 'Postlight' 'Mercury' 'API' -Mercury takes any web article and returns only the relevant content — headline, author, body text, relevant images and more — free from any clutter. +Mercury takes any web article and returns only the relevant content — headline, author, body text, relevant images and more — free from any clutter. You need an API key which you can get from [here](https://mercury.postlight.com). The following functions are implemented: @@ -35,7 +35,7 @@ dplyr::glimpse(just_the_facts(story)) ## $ title "Aircraft Carrier Wasn’t Sailing to Deter North Korea, as U.S. Suggested" ## $ content "
\n\n \n\n ... ## $ author "Mark Landler and Eric Schmitt" - ## $ date_published "2017-04-18T17:57:41.000Z" + ## $ date_published 2017-04-18 17:57:41 ## $ lead_image_url "https://static01.nyt.com/images/2017/04/19/world/19carrier-sub/19carrier-sub-facebookJumbo.... ## $ url "https://www.nytimes.com/2017/04/18/world/asia/aircraft-carrier-north-korea-carl-vinson.html" ## $ domain "www.nytimes.com" @@ -54,7 +54,7 @@ library(testthat) date() ``` - ## [1] "Wed Apr 19 10:16:35 2017" + ## [1] "Wed Apr 19 10:26:14 2017" ``` r test_dir("tests/") diff --git a/man/hgr.Rd b/man/hgr.Rd index f9eed04..59b101a 100644 --- a/man/hgr.Rd +++ b/man/hgr.Rd @@ -6,7 +6,7 @@ \alias{hgr-package} \title{Tools to Work with the 'Postlight' 'Mercury' 'API'} \description{ -Mercury takes any web article and returns only the relevant content — headline, author, +\href{https://mercury.postlight.com}{Mercury} takes any web article and returns only the relevant content — headline, author, body text, relevant images and more — free from any clutter. } \author{