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..46b0e57
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,8 @@
+# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r
+
+language: R
+sudo: false
+cache: packages
+global:
+ - R_CHECK_ARGS="--no-build-vignettes --no-manual --timings --no-tests"
+ - _R_CHECK_TIMINGS_="0"
diff --git a/DESCRIPTION b/DESCRIPTION
index 7627aed..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
-LazyData: true
-RoxygenNote: 5.0.1
VignetteBuilder: knitr
+LazyData: true
+RoxygenNote: 6.0.1
diff --git a/R/speed-insights-package.R b/R/speed-insights-package.R
index 75ab183..0f5bc80 100644
--- a/R/speed-insights-package.R
+++ b/R/speed-insights-package.R
@@ -6,25 +6,38 @@
#' @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))
- frame1 <- cbind(as.data.frame(pid[2]),as.data.frame(pid[3]),as.data.frame(pid[5]),as.data.frame(pid[6]))
+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))
+ 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
#'
#' 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.
+#' @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))
- frame1 <- cbind(as.data.frame(pid[2]),as.data.frame(pid[3]),as.data.frame(pid[5]),as.data.frame(pid[6]))
+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))
+ 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
@@ -32,16 +45,19 @@ 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.
+#' @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/README.md b/README.md
index 56fe1e0..cb1ec51 100644
--- a/README.md
+++ b/README.md
@@ -1,32 +1,37 @@
-#gpagespeed
+[![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.
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.
+# Functions in gpagespeed
-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:
+`speedfinder`
+The `speedfinder` function returns a dataframe with a single observation and columns of numeric data as its response. 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.
+* _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.
-#Example Usage
+`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:
-Below are examples of how the speedfinder and speedlist functions could be called in an R script.
+* _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.
-``` #get speed metrics for a single URL and assign it to a variable ```
+# Example Usage
-``` df1 <- speedfinder("https://www.cars.com","mobile","atextkeyigotfromgoogle111") ```
+Below are examples of how the `speedfinder` and `speedlist` functions could be called in an R script.
-``` #get speed metrics for a list of URLs and have it all returned in a single dataframe ```
+```
+# Get speed metrics for a single URL and assign it to a data frame
+df1 <- speedfinder("https://www.cars.com", "mobile", "atextkeyigotfromgoogle111")
-``` 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")
+```
diff --git a/man/speedfinder.Rd b/man/speedfinder.Rd
index 3b6a15a..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,11 +13,14 @@ 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.
}
\examples{
+\dontrun{
speedfinder("https://www.cars.com","mobile",key)
}
-
+}
diff --git a/man/speedfinder2.Rd b/man/speedfinder2.Rd
index 3b28d61..5898e93 100644
--- a/man/speedfinder2.Rd
+++ b/man/speedfinder2.Rd
@@ -4,10 +4,19 @@
\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.}
+
+\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{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
Insights API.
}
-
diff --git a/man/speedlist.Rd b/man/speedlist.Rd
index 7120c59..7f88923 100644
--- a/man/speedlist.Rd
+++ b/man/speedlist.Rd
@@ -4,21 +4,24 @@
\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.}
+
\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.}
+\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
each row contains the results from the API for a unique URL in the list.
}
\examples{
+\dontrun{
speedlist(listofURLs,"mobile",key)
}
-
+}
diff --git a/tests/testthat/testthat.R b/tests/testthat/testthat.R
index 2c1a450..b615b0c 100644
--- a/tests/testthat/testthat.R
+++ b/tests/testthat/testthat.R
@@ -5,16 +5,19 @@ 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", {
- 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)
})
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")
-
-```
-