From 3fecd1546557b2f41b27554d0e3b4a2a33e1e90a Mon Sep 17 00:00:00 2001 From: Manos Parzakonis Date: Thu, 9 Nov 2017 15:03:38 +0200 Subject: [PATCH 01/13] Update README.md --- README.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 56fe1e0..aae9364 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,32 @@ -#gpagespeed +# gpagespeed gpagespeed is a package designed to facilitate utilization of the Google PageSpeed Insights API. The PageSpeed Insights API provides insight into how Google's bots evaluate a given page, and the factors that web developers may wish to consider in building pages that will render faster. See Google's documentation on the PageSpeed Insights API to learn more about what the API offers as well as practical examples of its usage. The PageSpeed Insights API returns a numeric summary of the results of each page, as well as recommendations in text format. Currently, this package is designed to support only retrieving the numeric summary, which includes the overall speed score as well as metrics pertaining to the number of file requests and sizes in kilobytes of images, HTML, CSS, and JavaScript. The package offers two functions: speedfinder and speedlist. These functions are documented below. -#Functions in gpagespeed +# Functions in gpagespeed -1.speedfinder. The speedfinder function returns a dataframe with a single observation and columsn of numeric data as its response. It accepts three arguments: +`speedfinder` The `speedfinder` function returns a dataframe with a single observation and columsn of numeric data as its response. It accepts three arguments: -*_url_: The url argument refers to the url of the document on which the PageSpeed Insights API should be run and the corresponding summary metrics returned.
-*_strategy_: This argument should have one of two potential text string inputs: "desktop" or "mobile" to denote the device context that the PageSpeed Insights API should use in its evaluation.
-*_key_: This is the key that is required to use the API. [Visit Google's Developer Console](https://developers.google.com/console/help/using-keys) to obtain your free key. +* _url_: The url argument refers to the url of the document on which the PageSpeed Insights API should be run and the corresponding summary metrics returned. +* _strategy_: This argument should have one of two potential text string inputs: "`desktop`" or "`mobile`" to denote the device context that the PageSpeed Insights API should use in its evaluation. +* _key_: This is the key that is required to use the API. [Visit Google's Developer Console](https://developers.google.com/console/help/using-keys) to obtain your free key. -2.speedlist. The speedlist function is like the speedfinder function, but allows processing of many URLs and returns a dataframe in which each observation corresponds to a unique URL. Like speedfinder, it accepts three arguments: +`speedlist` The `speedlist` function is like the `speedfinder` function, but allows processing of many URLs and returns a dataframe in which each observation corresponds to a unique URL. Like `speedfinder`, it accepts three arguments: -*_pagelist_: A list object in which each item in the list is a URL listed as a character string.
-*_strategy_: This argument should have one of two potential text string inputs: "desktop" or "mobile" to denote the device context that the PageSpeed Insights API should use in its evaluation.
-*_key_: This is the key that is required to use the API. [Visit Google's Developer Console](https://developers.google.com/console/help/using-keys) to obtain your free key. +* _pagelist_: A list object in which each item in the list is a URL listed as a character string. +* _strategy_: This argument should have one of two potential text string inputs: "`desktop`" or "`mobile`" to denote the device context that the PageSpeed Insights API should use in its evaluation. +* _key_: This is the key that is required to use the API. [Visit Google's Developer Console](https://developers.google.com/console/help/using-keys) to obtain your free key. -#Example Usage +# Example Usage -Below are examples of how the speedfinder and speedlist functions could be called in an R script. +Below are examples of how the `speedfinder` and `speedlist` functions could be called in an R script. -``` #get speed metrics for a single URL and assign it to a variable ``` +``` # Get speed metrics for a single URL and assign it to a variable ``` ``` df1 <- speedfinder("https://www.cars.com","mobile","atextkeyigotfromgoogle111") ``` -``` #get speed metrics for a list of URLs and have it all returned in a single dataframe ``` +``` # Get speed metrics for a list of URLs and have it all returned in a single dataframe ``` ``` df2 <- speedlist(c("https://www.cars.com","http://www.yahoo.com","http://www.techmeme.com"), ``` ``` "mobile","atextkeyigotfromgoogle111") ``` From 2946cb7f5c49760e703a81f5ed48df1e7e62ae64 Mon Sep 17 00:00:00 2001 From: Manos Parzakonis Date: Thu, 9 Nov 2017 15:05:31 +0200 Subject: [PATCH 02/13] Update README.md --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index aae9364..91dad6b 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,9 @@ The PageSpeed Insights API returns a numeric summary of the results of each page # Functions in gpagespeed -`speedfinder` The `speedfinder` function returns a dataframe with a single observation and columsn of numeric data as its response. It accepts three arguments: +`speedfinder` The `speedfinder` function returns a dataframe with a single observation and columns of numeric data as its response. It accepts three arguments: -* _url_: The url argument refers to the url of the document on which the PageSpeed Insights API should be run and the corresponding summary metrics returned. +* _url_: The url argument refers to the URL of the document on which the PageSpeed Insights API should be run and the corresponding summary metrics returned. * _strategy_: This argument should have one of two potential text string inputs: "`desktop`" or "`mobile`" to denote the device context that the PageSpeed Insights API should use in its evaluation. * _key_: This is the key that is required to use the API. [Visit Google's Developer Console](https://developers.google.com/console/help/using-keys) to obtain your free key. @@ -24,9 +24,10 @@ Below are examples of how the `speedfinder` and `speedlist` functions could be c ``` # Get speed metrics for a single URL and assign it to a variable ``` -``` df1 <- speedfinder("https://www.cars.com","mobile","atextkeyigotfromgoogle111") ``` +``` df1 <- speedfinder("https://www.cars.com", "mobile", "atextkeyigotfromgoogle111") ``` ``` # Get speed metrics for a list of URLs and have it all returned in a single dataframe ``` -``` df2 <- speedlist(c("https://www.cars.com","http://www.yahoo.com","http://www.techmeme.com"), ``` -``` "mobile","atextkeyigotfromgoogle111") ``` +``` df2 <- speedlist(c("https://www.cars.com", "http://www.yahoo.com", "http://www.techmeme.com"), + "mobile", + "atextkeyigotfromgoogle111") ``` From d793a77e6b815b6844bc37c3b61902ca1e93e56f Mon Sep 17 00:00:00 2001 From: Manos Parzakonis Date: Thu, 9 Nov 2017 15:10:23 +0200 Subject: [PATCH 03/13] Update README.md --- README.md | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 91dad6b..83b1bc3 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,15 @@ The PageSpeed Insights API returns a numeric summary of the results of each page # Functions in gpagespeed -`speedfinder` The `speedfinder` function returns a dataframe with a single observation and columns of numeric data as its response. It accepts three arguments: +`speedfinder` +The `speedfinder` function returns a dataframe with a single observation and columns of numeric data as its response. It accepts three arguments: * _url_: The url argument refers to the URL of the document on which the PageSpeed Insights API should be run and the corresponding summary metrics returned. * _strategy_: This argument should have one of two potential text string inputs: "`desktop`" or "`mobile`" to denote the device context that the PageSpeed Insights API should use in its evaluation. * _key_: This is the key that is required to use the API. [Visit Google's Developer Console](https://developers.google.com/console/help/using-keys) to obtain your free key. -`speedlist` The `speedlist` function is like the `speedfinder` function, but allows processing of many URLs and returns a dataframe in which each observation corresponds to a unique URL. Like `speedfinder`, it accepts three arguments: +`speedlist` +The `speedlist` function is like the `speedfinder` function, but allows processing of many URLs and returns a dataframe in which each observation corresponds to a unique URL. Like `speedfinder`, it accepts three arguments: * _pagelist_: A list object in which each item in the list is a URL listed as a character string. * _strategy_: This argument should have one of two potential text string inputs: "`desktop`" or "`mobile`" to denote the device context that the PageSpeed Insights API should use in its evaluation. @@ -22,12 +24,12 @@ The PageSpeed Insights API returns a numeric summary of the results of each page Below are examples of how the `speedfinder` and `speedlist` functions could be called in an R script. -``` # Get speed metrics for a single URL and assign it to a variable ``` +``` +# Get speed metrics for a single URL and assign it to a data frame +df1 <- speedfinder("https://www.cars.com", "mobile", "atextkeyigotfromgoogle111") -``` df1 <- speedfinder("https://www.cars.com", "mobile", "atextkeyigotfromgoogle111") ``` - -``` # Get speed metrics for a list of URLs and have it all returned in a single dataframe ``` - -``` df2 <- speedlist(c("https://www.cars.com", "http://www.yahoo.com", "http://www.techmeme.com"), - "mobile", - "atextkeyigotfromgoogle111") ``` +# Get speed metrics for a list of URLs and have it all returned in a single data frame +df2 <- speedlist(c("https://www.cars.com", "http://www.yahoo.com", "http://www.techmeme.com"), + "mobile", + "atextkeyigotfromgoogle111") +``` From 919981091819b98fde602f002ce91757a55f2158 Mon Sep 17 00:00:00 2001 From: IronistM Date: Thu, 9 Nov 2017 15:20:53 +0200 Subject: [PATCH 04/13] Push travis --- .Rbuildignore | 1 + .travis.yml | 5 ++++ DESCRIPTION | 2 +- README.md | 2 ++ man/speedfinder.Rd | 1 - man/speedfinder2.Rd | 1 - man/speedlist.Rd | 1 - vignettes/my-vignette.Rmd | 48 --------------------------------------- 8 files changed, 9 insertions(+), 52 deletions(-) create mode 100644 .travis.yml delete mode 100644 vignettes/my-vignette.Rmd diff --git a/.Rbuildignore b/.Rbuildignore index 91114bf..112ad26 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,2 +1,3 @@ ^.*\.Rproj$ ^\.Rproj\.user$ +^\.travis\.yml$ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..8d139ac --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r + +language: R +sudo: false +cache: packages diff --git a/DESCRIPTION b/DESCRIPTION index 7627aed..efc734a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -20,5 +20,5 @@ Suggests: testthat License: GPL-3 LazyData: true -RoxygenNote: 5.0.1 +RoxygenNote: 6.0.1 VignetteBuilder: knitr diff --git a/README.md b/README.md index 83b1bc3..cb1ec51 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Travis-CI Build Status](https://travis-ci.org/IronistM/gpagespeed.svg?branch=master)](https://travis-ci.org/IronistM/gpagespeed) + # gpagespeed gpagespeed is a package designed to facilitate utilization of the Google PageSpeed Insights API. The PageSpeed Insights API provides insight into how Google's bots evaluate a given page, and the factors that web developers may wish to consider in building pages that will render faster. See Google's documentation on the PageSpeed Insights API to learn more about what the API offers as well as practical examples of its usage. diff --git a/man/speedfinder.Rd b/man/speedfinder.Rd index 3b6a15a..f70d051 100644 --- a/man/speedfinder.Rd +++ b/man/speedfinder.Rd @@ -20,4 +20,3 @@ The speedfinder function returns the Google Page Speed Insights test results for \examples{ speedfinder("https://www.cars.com","mobile",key) } - diff --git a/man/speedfinder2.Rd b/man/speedfinder2.Rd index 3b28d61..3451f44 100644 --- a/man/speedfinder2.Rd +++ b/man/speedfinder2.Rd @@ -10,4 +10,3 @@ speedfinder2(url, strategy, key) Speedfinder2 is a function utilized by speedlist to allow a list of URLs to be submitted to the Google Page Speed Insights API. } - diff --git a/man/speedlist.Rd b/man/speedlist.Rd index 7120c59..2ab1fc2 100644 --- a/man/speedlist.Rd +++ b/man/speedlist.Rd @@ -21,4 +21,3 @@ each row contains the results from the API for a unique URL in the list. \examples{ speedlist(listofURLs,"mobile",key) } - diff --git a/vignettes/my-vignette.Rmd b/vignettes/my-vignette.Rmd deleted file mode 100644 index 5bf91e2..0000000 --- a/vignettes/my-vignette.Rmd +++ /dev/null @@ -1,48 +0,0 @@ ---- -title: "Introduction to gpagespeed" -author: "Simit Patel" -date: "`r Sys.Date()`" -output: rmarkdown::html_vignette -vignette: > - %\VignetteIndexEntry{Introduction to gpagespeed} - %\VignetteEngine{knitr::rmarkdown} - %\VignetteEncoding{UTF-8} ---- - -## gpagespeed Introduction - -gpagespeed is a package designed to facilitate utilization of the Google PageSpeed Insights API. The PageSpeed Insights API provides insight into how Google's bots evaluate a given page, and the factors that web developers may wish to consider in building pages that will render faster. See Google's [documentation on the PageSpeed Insights API](https://developers.google.com/speed/docs/insights/about) to learn more about what the API offers as well as practical examples of its usage. - -The PageSpeed Insights API returns a numeric summary of the results of each page, as well as recommendations in text format. Currently, this package is designed to support only retrieving the numeric summary, which includes the overall speed score as well as metrics pertaining to the number of file requests and sizes in kilobytes of images, HTML, CSS, and JavaScript. The package offers two functions: __speedfinder__ and __speedlist__. These functions are documented below. - -## Functions in gpagespeed - -1.__speedfinder.__ The speedfinder function returns a dataframe with a single observation and columsn of numeric data as its response. It accepts three arguments: - - *_url_: The url argument refers to the url of the document on which the PageSpeed Insights API should be run and the corresponding summary metrics returned. - *_strategy_: This argument should have one of two potential text string inputs: "desktop" or "mobile" to denote the device context that the PageSpeed Insights API should use in its evaluation. - *_key_: This is the key that is required to use the API. [Visit Google's Developer Console](https://developers.google.com/console/help/using-keys) to obtain your free key. - - -1.__speedlist.__ The speedlist function is like the speedfinder function, but allows processing of many URLs and returns a dataframe in which each observation corresponds to a unique URL. Like speedfinder, it accepts three arguments: - - *_pagelist_: A list object in which each item in the list is a URL listed as a character string. - *_strategy_: This argument should have one of two potential text string inputs: "desktop" or "mobile" to denote the device context that the PageSpeed Insights API should use in its evaluation. - *_key_: This is the key that is required to use the API. [Visit Google's Developer Console](https://developers.google.com/console/help/using-keys) to obtain your free key. - -## Example Usage - -Below are examples of how the __speedfinder__ and __speedlist__ functions could be called in an R script. - -```{r, results='hide'} -#get speed metrics for a single URL and assign it to a variable - -df1 <- speedfinder("https://www.cars.com","mobile","atextkeyigotfromgoogle111") - -#get speed metrics for a list of URLs and have it all returned in a single dataframe - -df2 <- speedlist(c("https://www.cars.com","http://www.yahoo.com","http://www.techmeme.com"), - "mobile","atextkeyigotfromgoogle111") - -``` - From 7e009a7cae3d31c063ce1897a9539890515db23f Mon Sep 17 00:00:00 2001 From: IronistM Date: Thu, 9 Nov 2017 15:40:30 +0200 Subject: [PATCH 05/13] Fixed documentation problem --- R/speed-insights-package.R | 6 +++++- man/speedfinder2.Rd | 8 ++++++++ man/speedlist.Rd | 4 ++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/R/speed-insights-package.R b/R/speed-insights-package.R index 75ab183..f057137 100644 --- a/R/speed-insights-package.R +++ b/R/speed-insights-package.R @@ -20,6 +20,10 @@ speedfinder <- function(url,strategy,key) { #' #' Speedfinder2 is a function utilized by speedlist to allow a list of URLs to be submitted to the Google Page Speed #' Insights API. +#' @param url A list of URLs on which to run the Google Page Speed Insights test. +#' @param strategy Whether the list of URLs should be evaluated in a mobile or desktop context. Accordingly, acceptable values +#' are either the string "mobile" or the string "desktop". +#' @param key A unique key obtainable from Google by registering for free as a Google developer. #' @export speedfinder2 <- function(url,strategy,key) { @@ -32,7 +36,7 @@ speedfinder2 <- function(url,strategy,key) { #' The speedlist function submits a list of URLs to the Google Page Speed Insights API, and returns a dataframe in which #' each row contains the results from the API for a unique URL in the list. #' -#' @param url A list of URLs on which to run the Google Page Speed Insights test. +#' @param pagelist A list of URLs on which to run the Google Page Speed Insights test. #' @param strategy Whether the list of URLs should be evaluated in a mobile or desktop context. Accordingly, acceptable values #' are either the string "mobile" or the string "desktop". #' @param key A unique key obtainable from Google by registering for free as a Google developer. diff --git a/man/speedfinder2.Rd b/man/speedfinder2.Rd index 3451f44..f3ad7e7 100644 --- a/man/speedfinder2.Rd +++ b/man/speedfinder2.Rd @@ -6,6 +6,14 @@ \usage{ speedfinder2(url, strategy, key) } +\arguments{ +\item{url}{A list of URLs on which to run the Google Page Speed Insights test.} + +\item{strategy}{Whether the list of URLs should be evaluated in a mobile or desktop context. Accordingly, acceptable values +are either the string "mobile" or the string "desktop".} + +\item{key}{A unique key obtainable from Google by registering for free as a Google developer.} +} \description{ Speedfinder2 is a function utilized by speedlist to allow a list of URLs to be submitted to the Google Page Speed Insights API. diff --git a/man/speedlist.Rd b/man/speedlist.Rd index 2ab1fc2..2d9460a 100644 --- a/man/speedlist.Rd +++ b/man/speedlist.Rd @@ -7,12 +7,12 @@ speedlist(pagelist, strategy, key) } \arguments{ +\item{pagelist}{A list of URLs on which to run the Google Page Speed Insights test.} + \item{strategy}{Whether the list of URLs should be evaluated in a mobile or desktop context. Accordingly, acceptable values are either the string "mobile" or the string "desktop".} \item{key}{A unique key obtainable from Google by registering for free as a Google developer.} - -\item{url}{A list of URLs on which to run the Google Page Speed Insights test.} } \description{ The speedlist function submits a list of URLs to the Google Page Speed Insights API, and returns a dataframe in which From dc711f941e9fec1da7f7b849172b784cb0d392ce Mon Sep 17 00:00:00 2001 From: IronistM Date: Thu, 9 Nov 2017 15:40:56 +0200 Subject: [PATCH 06/13] Ignoring tests that rely on authentication --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 09a72cb..4f25749 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .Rhistory .RData inst/doc +tests/testthat From 9748997507a7386061d817a9c52f0b6c0f3c7572 Mon Sep 17 00:00:00 2001 From: Manos Parzakonis Date: Thu, 9 Nov 2017 16:44:16 +0200 Subject: [PATCH 07/13] Update .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 4f25749..0da3744 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ .Rhistory .RData inst/doc -tests/testthat +tests/testthat/* From 67f6607fd2d538a2586a3d38dab592b6fce1983e Mon Sep 17 00:00:00 2001 From: IronistM Date: Thu, 9 Nov 2017 16:49:12 +0200 Subject: [PATCH 08/13] Opt for dontrun{} in @examples --- R/speed-insights-package.R | 4 ++++ man/speedfinder.Rd | 2 ++ man/speedlist.Rd | 2 ++ 3 files changed, 8 insertions(+) diff --git a/R/speed-insights-package.R b/R/speed-insights-package.R index f057137..69c5ead 100644 --- a/R/speed-insights-package.R +++ b/R/speed-insights-package.R @@ -7,7 +7,9 @@ #' are either the string "mobile" or the string "desktop". #' @param key A unique key obtainable from Google by registering for free as a Google developer. #' @examples +#' \dontrun{ #' speedfinder("https://www.cars.com","mobile",key) +#' } #' @export speedfinder <- function(url,strategy,key) { @@ -41,7 +43,9 @@ speedfinder2 <- function(url,strategy,key) { #' are either the string "mobile" or the string "desktop". #' @param key A unique key obtainable from Google by registering for free as a Google developer. #' @examples +#' \dontrun{ #' speedlist(listofURLs,"mobile",key) +#' } #' @export speedlist <- function(pagelist,strategy,key) { diff --git a/man/speedfinder.Rd b/man/speedfinder.Rd index f70d051..079eaec 100644 --- a/man/speedfinder.Rd +++ b/man/speedfinder.Rd @@ -18,5 +18,7 @@ are either the string "mobile" or the string "desktop".} The speedfinder function returns the Google Page Speed Insights test results for a single URL as a dataframe. } \examples{ +\dontrun{ speedfinder("https://www.cars.com","mobile",key) } +} diff --git a/man/speedlist.Rd b/man/speedlist.Rd index 2d9460a..5dee73e 100644 --- a/man/speedlist.Rd +++ b/man/speedlist.Rd @@ -19,5 +19,7 @@ The speedlist function submits a list of URLs to the Google Page Speed Insights each row contains the results from the API for a unique URL in the list. } \examples{ +\dontrun{ speedlist(listofURLs,"mobile",key) } +} From e7ddc5e9716620951915a1331c827369f9feb2e7 Mon Sep 17 00:00:00 2001 From: IronistM Date: Thu, 9 Nov 2017 17:01:57 +0200 Subject: [PATCH 09/13] Restored tests --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0da3744..09a72cb 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,3 @@ .Rhistory .RData inst/doc -tests/testthat/* From 0c2ac197dcebe7d9c7e6fd9185c02b823fab1008 Mon Sep 17 00:00:00 2001 From: IronistM Date: Thu, 9 Nov 2017 17:02:29 +0200 Subject: [PATCH 10/13] Ignoring tests in Travis CI --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 8d139ac..46b0e57 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,3 +3,6 @@ language: R sudo: false cache: packages +global: + - R_CHECK_ARGS="--no-build-vignettes --no-manual --timings --no-tests" + - _R_CHECK_TIMINGS_="0" From 6d19a44c2533ed9ea2756228f4c637df5bf702be Mon Sep 17 00:00:00 2001 From: IronistM Date: Thu, 9 Nov 2017 17:23:47 +0200 Subject: [PATCH 11/13] Added filter_third_party_resources as a parameter --- R/speed-insights-package.R | 15 +++++++++------ man/speedfinder.Rd | 4 +++- man/speedfinder2.Rd | 4 +++- man/speedlist.Rd | 4 +++- tests/testthat/testthat.R | 10 ++++++---- 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/R/speed-insights-package.R b/R/speed-insights-package.R index 69c5ead..b3ee7bc 100644 --- a/R/speed-insights-package.R +++ b/R/speed-insights-package.R @@ -6,14 +6,15 @@ #' @param strategy Whether the URL should be evaluated in a mobile or desktop context. Accordingly, acceptable values #' are either the string "mobile" or the string "desktop". #' @param key A unique key obtainable from Google by registering for free as a Google developer. +#' @param filter_third_party_resources A boolean to indicate if third party resources should be filtered out before PageSpeed analysis. (Default: FALSE) #' @examples #' \dontrun{ #' speedfinder("https://www.cars.com","mobile",key) #' } #' @export -speedfinder <- function(url,strategy,key) { - pid <- RJSONIO::fromJSON(paste0("https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=",url,"&strategy=",strategy,"&key=",key)) +speedfinder <- function(url,strategy,key,filter_third_party_resources=FALSE) { + pid <- RJSONIO::fromJSON(paste0("https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=",url,"&strategy=",strategy,"&key=",key,"&filter_third_party_resources=",filter_third_party_resources)) frame1 <- cbind(as.data.frame(pid[2]),as.data.frame(pid[3]),as.data.frame(pid[5]),as.data.frame(pid[6])) rbind.data.frame(data.frame(), frame1,make.row.names=FALSE) } @@ -26,10 +27,11 @@ speedfinder <- function(url,strategy,key) { #' @param strategy Whether the list of URLs should be evaluated in a mobile or desktop context. Accordingly, acceptable values #' are either the string "mobile" or the string "desktop". #' @param key A unique key obtainable from Google by registering for free as a Google developer. +#' @param filter_third_party_resources A boolean to indicate if third party resources should be filtered out before PageSpeed analysis. (Default: FALSE) #' @export -speedfinder2 <- function(url,strategy,key) { - pid <- RJSONIO::fromJSON(paste0("https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=",url,"&strategy=",strategy,"&key=",key)) +speedfinder2 <- function(url,strategy,key,filter_third_party_resources=FALSE) { + pid <- RJSONIO::fromJSON(paste0("https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=",url,"&strategy=",strategy,"&key=",key,"&filter_third_party_resources=",filter_third_party_resources)) frame1 <- cbind(as.data.frame(pid[2]),as.data.frame(pid[3]),as.data.frame(pid[5]),as.data.frame(pid[6])) } @@ -42,14 +44,15 @@ speedfinder2 <- function(url,strategy,key) { #' @param strategy Whether the list of URLs should be evaluated in a mobile or desktop context. Accordingly, acceptable values #' are either the string "mobile" or the string "desktop". #' @param key A unique key obtainable from Google by registering for free as a Google developer. +#' @param filter_third_party_resources A boolean to indicate if third party resources should be filtered out before PageSpeed analysis. (Default: FALSE) #' @examples #' \dontrun{ #' speedlist(listofURLs,"mobile",key) #' } #' @export -speedlist <- function(pagelist,strategy,key) { - list1 <- lapply(pagelist,speedfinder2,strategy,key) +speedlist <- function(pagelist,strategy,key,filter_third_party_resources=FALSE) { + list1 <- lapply(pagelist,speedfinder2,strategy,key,filter_third_party_resources) suppressWarnings(do.call(gtools::smartbind,list1)) } diff --git a/man/speedfinder.Rd b/man/speedfinder.Rd index 079eaec..d5057ef 100644 --- a/man/speedfinder.Rd +++ b/man/speedfinder.Rd @@ -4,7 +4,7 @@ \alias{speedfinder} \title{Speed results for 1 URL} \usage{ -speedfinder(url, strategy, key) +speedfinder(url, strategy, key, filter_third_party_resources = FALSE) } \arguments{ \item{url}{A URL on which to run the Google Page Speed Insights test.} @@ -13,6 +13,8 @@ speedfinder(url, strategy, key) are either the string "mobile" or the string "desktop".} \item{key}{A unique key obtainable from Google by registering for free as a Google developer.} + +\item{filter_third_party_resources}{A boolean to indicate if third party resources should be filtered out before PageSpeed analysis. (Default: FALSE)} } \description{ The speedfinder function returns the Google Page Speed Insights test results for a single URL as a dataframe. diff --git a/man/speedfinder2.Rd b/man/speedfinder2.Rd index f3ad7e7..5898e93 100644 --- a/man/speedfinder2.Rd +++ b/man/speedfinder2.Rd @@ -4,7 +4,7 @@ \alias{speedfinder2} \title{Function within speedlist} \usage{ -speedfinder2(url, strategy, key) +speedfinder2(url, strategy, key, filter_third_party_resources = FALSE) } \arguments{ \item{url}{A list of URLs on which to run the Google Page Speed Insights test.} @@ -13,6 +13,8 @@ speedfinder2(url, strategy, key) are either the string "mobile" or the string "desktop".} \item{key}{A unique key obtainable from Google by registering for free as a Google developer.} + +\item{filter_third_party_resources}{A boolean to indicate if third party resources should be filtered out before PageSpeed analysis. (Default: FALSE)} } \description{ Speedfinder2 is a function utilized by speedlist to allow a list of URLs to be submitted to the Google Page Speed diff --git a/man/speedlist.Rd b/man/speedlist.Rd index 5dee73e..7f88923 100644 --- a/man/speedlist.Rd +++ b/man/speedlist.Rd @@ -4,7 +4,7 @@ \alias{speedlist} \title{Speed results for a list of URLs} \usage{ -speedlist(pagelist, strategy, key) +speedlist(pagelist, strategy, key, filter_third_party_resources = FALSE) } \arguments{ \item{pagelist}{A list of URLs on which to run the Google Page Speed Insights test.} @@ -13,6 +13,8 @@ speedlist(pagelist, strategy, key) are either the string "mobile" or the string "desktop".} \item{key}{A unique key obtainable from Google by registering for free as a Google developer.} + +\item{filter_third_party_resources}{A boolean to indicate if third party resources should be filtered out before PageSpeed analysis. (Default: FALSE)} } \description{ The speedlist function submits a list of URLs to the Google Page Speed Insights API, and returns a dataframe in which diff --git a/tests/testthat/testthat.R b/tests/testthat/testthat.R index 2c1a450..b14e3d0 100644 --- a/tests/testthat/testthat.R +++ b/tests/testthat/testthat.R @@ -5,16 +5,18 @@ context("gpagespeed functions") test_check("gpagespeed") +gspeed_key = 'YOUR_API_KEY' + test_that("speedfinder function", { - expect_equal(class(speedfinder("https://www.cars.com","mobile",key)), + expect_equal(class(speedfinder("https://www.cars.com","mobile",key=gspeed_key,filter_third_party_resources = TRUE)), class(data.frame())) - expect_equal(nrow(speedfinder("https://www.cars.com","mobile",key)), 1) + expect_equal(nrow(speedfinder("https://www.cars.com","mobile",key=gspeed_key)), 1) }) test_that("speedlist function", { expect_equal(class(speedlist(c("https://www.cars.com","https://www.yahoo.com","https://www.techmeme.com"), - "mobile",key)), + "mobile",key=gspeed_key)), class(data.frame())) expect_equal(nrow(speedlist(c("https://www.cars.com","https://www.yahoo.com","https://www.techmeme.com"), - "mobile",key)), 3) + "mobile",key=gspeed_key)), 3) }) From 0797d9cbe4760d02bc11f11d86ed32314c4ee0a2 Mon Sep 17 00:00:00 2001 From: IronistM Date: Thu, 9 Nov 2017 17:34:25 +0200 Subject: [PATCH 12/13] Added contribution & normalised DESCRIPTION --- DESCRIPTION | 27 ++++++++++++++++++--------- tests/testthat/testthat.R | 1 + 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index efc734a..63d14f4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,13 +1,23 @@ Package: gpagespeed Title: Google Page Speed API -Version: 0.0.0.9000 -Authors@R: person("Simit", "Patel", email = "simitp@gmail.com", role = c("aut", "cre")) -Description: A way to call the Google Page Speed Insights API directly into your - R console. The package offers two functions that return results the API in the - form of a data frame. The first function, speedfinder, is to call the results - on a single URL, while the second function, speedlist, accepts a list of URLs - and returns a single dataframe with results from the API for all the URLs in the +Version: 0.0.1 +Authors@R: + c(person(given = "Simit", + family = "Patel", + role = c("aut", "cre"), + email = "simitp@gmail.com"), + person(given = "Manos", + family = "Parzakonis", + role = "ctb", + email = "parzakonis.m@gmail.com")) +Description: A way to call the Google Page Speed Insights API + directly into your R console. The package offers two functions that + return results the API in the form of a data frame. The first + function, speedfinder, is to call the results on a single URL, while + the second function, speedlist, accepts a list of URLs and returns a + single dataframe with results from the API for all the URLs in the list. +License: GPL-3 Depends: R (>= 3.2.3) Imports: @@ -18,7 +28,6 @@ Suggests: knitr, rmarkdown, testthat -License: GPL-3 +VignetteBuilder: knitr LazyData: true RoxygenNote: 6.0.1 -VignetteBuilder: knitr diff --git a/tests/testthat/testthat.R b/tests/testthat/testthat.R index b14e3d0..b615b0c 100644 --- a/tests/testthat/testthat.R +++ b/tests/testthat/testthat.R @@ -5,6 +5,7 @@ context("gpagespeed functions") test_check("gpagespeed") +# Need to set an API key to run the tests gspeed_key = 'YOUR_API_KEY' test_that("speedfinder function", { From f5c0bc5b5016468a3bf82bb052bb0df0a745cded Mon Sep 17 00:00:00 2001 From: IronistM Date: Fri, 10 Nov 2017 09:57:29 +0200 Subject: [PATCH 13/13] Don't store data as factor, store numerical data as numeric --- R/speed-insights-package.R | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/R/speed-insights-package.R b/R/speed-insights-package.R index b3ee7bc..0f5bc80 100644 --- a/R/speed-insights-package.R +++ b/R/speed-insights-package.R @@ -15,8 +15,11 @@ #' @export speedfinder <- function(url,strategy,key,filter_third_party_resources=FALSE) { pid <- RJSONIO::fromJSON(paste0("https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=",url,"&strategy=",strategy,"&key=",key,"&filter_third_party_resources=",filter_third_party_resources)) - frame1 <- cbind(as.data.frame(pid[2]),as.data.frame(pid[3]),as.data.frame(pid[5]),as.data.frame(pid[6])) + tmp <- as.data.frame(pid[6], stringsAsFactors=FALSE) + tmp <- as.data.frame(lapply(tmp, as.numeric), stringsAsFactors=FALSE) + frame1 <- cbind(as.data.frame(pid[2], stringsAsFactors=FALSE),as.data.frame(pid[3], stringsAsFactors=FALSE),as.data.frame(pid[5], stringsAsFactors=FALSE), tmp) rbind.data.frame(data.frame(), frame1,make.row.names=FALSE) + } #' Function within speedlist @@ -32,7 +35,9 @@ speedfinder <- function(url,strategy,key,filter_third_party_resources=FALSE) { #' @export speedfinder2 <- function(url,strategy,key,filter_third_party_resources=FALSE) { pid <- RJSONIO::fromJSON(paste0("https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=",url,"&strategy=",strategy,"&key=",key,"&filter_third_party_resources=",filter_third_party_resources)) - frame1 <- cbind(as.data.frame(pid[2]),as.data.frame(pid[3]),as.data.frame(pid[5]),as.data.frame(pid[6])) + tmp <- as.data.frame(pid[6], stringsAsFactors=FALSE) + tmp <- as.data.frame(lapply(tmp, as.numeric), stringsAsFactors=FALSE) + frame1 <- cbind(as.data.frame(pid[2], stringsAsFactors=FALSE),as.data.frame(pid[3], stringsAsFactors=FALSE),as.data.frame(pid[5], stringsAsFactors=FALSE), tmp) } #' Speed results for a list of URLs