Skip to content

Commit

Permalink
Removed all non-standard evaluation from package.
Browse files Browse the repository at this point in the history
  • Loading branch information
amarder committed Jun 9, 2016
1 parent e2a49be commit bf4c69d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 38 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ importFrom(igraph,plot.igraph)
importFrom(lubridate,dminutes)
importFrom(lubridate,floor_date)
importFrom(lubridate,ymd_hms)
importFrom(tidyr,separate)
importFrom(tidyr,separate_)
importFrom(utils,head)
importFrom(utils,read.csv)
importFrom(utils,str)
5 changes: 3 additions & 2 deletions R/data_retrieval.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#' @import RMySQL
#' @importFrom lubridate ymd_hms floor_date
#' @importFrom utils str read.csv
NULL

#' @export
dplyr::src_mysql
Expand Down Expand Up @@ -69,8 +70,8 @@ get_actions <- function(db) {
time_to_serve = "custom_float",
time_spent_on_previous_action = "time_spent_ref_action"
) %>%
mutate(datetime = ymd_hms(datetime)) %>%
mutate(day = floor_date(datetime, "day"))
mutate_(datetime = ~ ymd_hms(datetime)) %>%
mutate_(day = ~ floor_date(datetime, "day"))

return(actions)
}
Expand Down
53 changes: 23 additions & 30 deletions R/graphs.R
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
#' @import ggplot2
#' @importFrom tidyr separate
#' @importFrom tidyr separate_
#' @importFrom lubridate dminutes
#' @importFrom igraph graph_from_data_frame E V layout.auto plot.igraph

globalVariables(c(
"previous_page",
"datetime",
"visit_id",
"proportion",
"height",
"width",
"config_resolution",
"page"
))
NULL

#' Graph number of visitors over time.
#'
#' @param days Table of days.
#' @export
#'
graph_visitors_vs_date <- function(days) {
g <- (
ggplot(days, aes_string(x = "day_of_first_visit", y = "new_visitors")) +
Expand All @@ -35,17 +26,18 @@ graph_visitors_vs_date <- function(days) {
#'
#' @param visits Table of visits.
#' @export
#'
graph_browser_resolutions <- function(visits) {
resolutions <- visits %>%
separate(config_resolution, c("width", "height"), sep = "x", convert = TRUE, fill = "right") %>%
group_by(width, height) %>%
filter(!is.na(width), !is.na(height)) %>%
summarise(n = n()) %>%
separate_("config_resolution", c("width", "height"), sep = "x", convert = TRUE, fill = "right") %>%
group_by_("width", "height") %>%
filter_("!is.na(width)", "!is.na(height)") %>%
summarise_(n = "n()") %>%
ungroup() %>%
mutate(proportion = n / sum(n))
mutate_(proportion = "n / sum(n)")

(
ggplot(resolutions, aes(xmin = 0, xmax = width, ymin = 0, ymax = height, alpha = proportion)) +
ggplot(resolutions, aes_string(xmin = 0, xmax = "width", ymin = 0, ymax = "height", alpha = "proportion")) +
geom_rect(fill = NA, color = "black") +
theme_classic() +
guides(alpha = guide_legend(title = "Proportion\nof Visits", override.aes = list(fill = "black", color = "white"))) +
Expand All @@ -60,28 +52,29 @@ graph_browser_resolutions <- function(visits) {
#'
#' @param actions Table of actions.
#' @export
#'
graph_site_structure <- function(actions) {
views <- actions %>%
filter(grepl("amarder.github.io", url)) %>%
mutate(page = sub("amarder.github.io", "", url))
filter_("grepl('amarder.github.io', url)") %>%
mutate_(page = "sub('amarder.github.io', '', url)")

pages <- views %>%
group_by(page) %>%
summarise(n = n()) %>%
group_by_("page") %>%
summarise_(n = "n()") %>%
ungroup() %>%
mutate(page_id = row_number(n))
mutate_(page_id = "row_number(n)")

views <- views %>%
group_by(visit_id) %>%
mutate(t = (datetime - min(datetime)) / dminutes(1), n = n()) %>%
arrange(datetime) %>%
mutate(previous_page = lag(page)) %>%
group_by_("visit_id") %>%
mutate_(t = ~ (datetime - min(datetime)) / dminutes(1), n = "n()") %>%
arrange_("datetime") %>%
mutate_(previous_page = "lag(page)") %>%
ungroup()

edges <- views %>%
filter(!is.na(previous_page), previous_page != page) %>%
group_by(previous_page, page) %>%
summarise(n = n())
filter_("!is.na(previous_page)", "previous_page != page") %>%
group_by_("previous_page", "page") %>%
summarise_(n = "n()")

g <- graph_from_data_frame(edges, directed = TRUE, vertices = pages)
edge_importance <- 5 * E(g)$n / max(E(g)$n)
Expand Down
6 changes: 3 additions & 3 deletions R/munging.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ compute_visitors <- function(actions) {
compute_pages <- function(actions) {
pages <- actions %>%
group_by(url) %>%
summarise(n = length(unique(visitor_id))) %>%
arrange(desc(n)) %>%
filter(grepl("amarder.github.io", url)) %>%
summarise_(n = "length(unique(visitor_id))") %>%
arrange_("desc(n)") %>%
filter_("grepl('amarder.github.io', url)") %>%
mutate_(Page = "sub('amarder.github.io', '', url)", Visitors = "n") %>%
select_("Page", "Visitors")

Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,3 @@ devtools::install_github('amarder/piwikr')
## Notes

[This page](https://developer.piwik.org/guides/persistence-and-the-mysql-backend) was useful in understanding the data stored by Piwik in MySQL.

[This Stack Overflow answer](http://stackoverflow.com/a/12429344/3756632) describes my current approach to suppressing notes from `R CMD check` that are created by my use of non-standard evaluation.

0 comments on commit bf4c69d

Please sign in to comment.