Bearloga has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/356470 )
Change subject: Update dataset path, downloaded prefixes, and documentation ...................................................................... Update dataset path, downloaded prefixes, and documentation - Updates dataset of prefixes - Changes path to download datasets from - Uses latest roxygen with markdown support Bug: T166724 Change-Id: I34172c3198624425f6dfe55358d79e964791137a --- M DESCRIPTION M NEWS.md M R/check_notify.R M R/data.R M R/dygraphs.R M R/manipulate.R M R/maths.R M R/reading.R M R/shiny.R M R/smoothing.R M R/utils.R M README.md M inst/extdata/prefixes.csv M man/automata_select.Rd M man/cbind_fill.Rd M man/check_notify.Rd M man/compress.Rd M man/cond_color.Rd M man/cond_icon.Rd M man/custom_axis_formatter.Rd M man/data_select.Rd M man/get_langproj.Rd M man/get_prefixes.Rd M man/get_projects.Rd M man/half.Rd M man/make_dygraph.Rd M man/na_box.Rd M man/parse_wikiid.Rd M man/percent_change.Rd M man/read_dataset.Rd M man/safe_tail.Rd M man/smart_palette.Rd M man/smooth_select.Rd M man/smooth_switch.Rd M man/smoother.Rd M man/subset_by_date_range.Rd M man/time_frame_range.Rd M man/timeframe_daterange.Rd M man/timeframe_select.Rd M man/update_prefixes.Rd M man/update_projects.Rd 41 files changed, 276 insertions(+), 304 deletions(-) Approvals: Bearloga: Verified; Looks good to me, approved diff --git a/DESCRIPTION b/DESCRIPTION index 86c6f83..5435797 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,17 +1,17 @@ Package: polloi Type: Package Title: Common Functionality for Wikimedia Dashboards -Version: 0.1.7 -Date: 2016-12-07 +Version: 0.1.8 +Date: 2017-05-31 Authors@R: c( - person("Oliver", "Keyes", role = "aut"), - person("Mikhail", "Popov", email = "mpo...@wikimedia.org", role = c("aut", "cre"))) + person("Mikhail", "Popov", email = "mpo...@wikimedia.org", role = c("aut", "cre")), + person("Oliver", "Keyes", role = "aut") + ) Description: This package contains common functionality for all of the Wikimedia Foundation's Shiny Dashboards. License: MIT + file LICENSE URL: https://phabricator.wikimedia.org/diffusion/WDPL/ -BugReports: https://phabricator.wikimedia.org/maniphest/task/create/? - projects=Discovery-Analysis +BugReports: https://phabricator.wikimedia.org/maniphest/task/create/?projects=Discovery-Analysis Depends: R (>= 3.1.0) Imports: @@ -28,9 +28,10 @@ dplyr (>= 0.4.3), tidyr (>= 0.4.1), mgcv -LazyData: TRUE -RoxygenNote: 5.0.1 Suggests: rvest (>= 0.3.1), xml2 (>= 0.1.2), httr (>= 1.1.0) +LazyData: TRUE +Roxygen: list(markdown = TRUE) +RoxygenNote: 6.0.1 diff --git a/NEWS.md b/NEWS.md index b8cfd3a..28f0995 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +polloi 0.1.8 +============ +- Updates dataset of prefixes +- Changes path to download datasets from +- Uses latest roxygen with markdown support + polloi 0.1.7 ============ - Fixes a bug wherein a "found duplicated data in" message was incorrectly displayed (specifically, when there was no duplicated data). diff --git a/R/check_notify.R b/R/check_notify.R index 5492e60..1e5c840 100644 --- a/R/check_notify.R +++ b/R/check_notify.R @@ -1,17 +1,17 @@ -#'@title Check 'n' Notify -#'@description Check a dataset for missing data from the day before and the -#' past week, and create a \code{notificationItem} if missing data has been +#' @title Check 'n' Notify +#' @description Check a dataset for missing data from the day before and the +#' past week, and create a `notificationItem` if missing data has been #' detected. -#'@param dataset A data.frame with a 'date' column. -#'@param label The label to use in the notification. -#'@family Shiny Dashboarding -#'@name check_notify +#' @param dataset A data.frame with a 'date' column. +#' @param label The label to use in the notification. +#' @family Shiny Dashboarding +#' @name check_notify NULL -#'@rdname check_notify -#'@importFrom shinydashboard notificationItem -#'@importFrom shiny icon -#'@export +#' @rdname check_notify +#' @importFrom shinydashboard notificationItem +#' @importFrom shiny icon +#' @export check_yesterday <- function(dataset, label) { # e.g. label = "desktop events" yesterday_date <- Sys.Date() - 1 @@ -22,10 +22,10 @@ return(NULL) } -#'@rdname check_notify -#'@importFrom shinydashboard notificationItem -#'@importFrom shiny icon -#'@export +#' @rdname check_notify +#' @importFrom shinydashboard notificationItem +#' @importFrom shiny icon +#' @export check_past_week <- function(dataset, label) { past_week <- Sys.Date() - c(2:7) # Sys.Date()-1 is already handled by check_yesterday() if (any(!(past_week %in% dataset$date))) { diff --git a/R/data.R b/R/data.R index 2dfc8d4..288de6e 100644 --- a/R/data.R +++ b/R/data.R @@ -17,7 +17,7 @@ #' #' @source \url{https://meta.wikimedia.org/wiki/Template:Table_of_Wikimedia_projects#Projects_per_language_codes} #' @importFrom readr read_csv -#' @seealso \code{\link{update_prefixes}}, \code{\link{get_projects}}, \code{\link{get_langproj}} +#' @seealso [update_prefixes], [get_projects], [get_langproj] #' @export get_prefixes <- function() { return(readr::read_csv(system.file("extdata/prefixes.csv", package = "polloi"))) @@ -37,7 +37,7 @@ #' #' @source \url{https://meta.wikimedia.org/wiki/Table_of_Wikimedia_projects} #' @importFrom readr read_csv -#' @seealso \code{\link{update_projects}}, \code{\link{get_prefixes}}, \code{\link{get_langproj}} +#' @seealso [update_projects], [get_prefixes], [get_langproj] #' @export get_projects <- function() { return(readr::read_csv(system.file("extdata/projects.csv", package = "polloi"))) @@ -50,10 +50,10 @@ #' of languages and projects to be up-to-date, because it is not usually #' updated when a new wiki is deployed. The product method ensures that all #' the multilingual wikis are correctly captured (provided we have the -#' latest prefixes) by \code{\link{parse_wikiid}}. +#' latest prefixes) by [parse_wikiid]. #' @importFrom magrittr "%>%" #' @importFrom tidyr separate -#' @seealso \code{\link{get_prefixes}}, \code{\link{get_projects}} +#' @seealso [get_prefixes], [get_projects] #' @export get_langproj <- function() { prefixes <- get_prefixes() diff --git a/R/dygraphs.R b/R/dygraphs.R index c04462d..2a503c2 100644 --- a/R/dygraphs.R +++ b/R/dygraphs.R @@ -4,7 +4,7 @@ #' from RColorBrewer. For More than 12 categories, builds a HCL color #' space-based palette. #'@param n Number of colors to return (number of categories). -#'@return A character vector of \code{n} colors. +#'@return A character vector of `n` colors. #'@importFrom RColorBrewer brewer.pal #'@importFrom colorspace rainbow_hcl #'@export @@ -34,30 +34,30 @@ } } -#'@title Construct a Standard Wikimedia Discovery Dygraph -#'@description Construct a dygraph using the custom formatting Wikimedia -#' dashboards use as standard. This is nothing special - a standard dygraph -#' with a bit of custom CSS shipped with the package - but it's surrounded by -#' code that allows the function to turn all our usual data.frame formats -#' into XTS objects. -#'@param data a data.frame reformatted to be XTS-able. -#'@param xlab the label to use for the dygraph's x-axis. -#'@param ylab the label to use for the dygraph's y-axis. -#'@param title the title to use on the dygraph. -#'@param legend_name a custom name for the variable in the event that -#' \code{is_single} is TRUE. NULL by default (in which case the variable -#' will be named "events"). -#'@param use_si whether to use si labelling (1000 becomes 1K). TRUE by default. -#'@param expr an optional expression to evaluate prior to building the dygraph. -#' We use this in (for example) reactive graphing. -#'@param group Group to associate this plot with. The x-axis zoom level of -#' plots within a group is automatically synchronized. -#'@param ... Additional parameters to pass on to \code{dyOptions}. -#'@importFrom dygraphs renderDygraph dyCSS dyOptions dyLegend dygraph -#'@importFrom xts xts -#'@importFrom RColorBrewer brewer.pal -#'@importFrom magrittr "%>%" -#'@export +#' @title Construct a Standard Wikimedia Discovery Dygraph +#' @description Construct a dygraph using the custom formatting Wikimedia +#' dashboards use as standard. This is nothing special - a standard dygraph +#' with a bit of custom CSS shipped with the package - but it's surrounded by +#' code that allows the function to turn all our usual `data.frame` formats +#' into [xts::xts] objects. +#' @param data a `data.frame` reformatted to be XTS-able. +#' @param xlab the label to use for the dygraph's x-axis. +#' @param ylab the label to use for the dygraph's y-axis. +#' @param title the title to use on the dygraph. +#' @param legend_name a custom name for the variable in the event that +#' `is_single` is TRUE. NULL by default (in which case the variable +#' will be named "events"). +#' @param use_si whether to use si labelling (1000 becomes 1K). TRUE by default. +#' @param expr an optional expression to evaluate prior to building the dygraph. +#' We use this in (for example) reactive graphing. +#' @param group Group to associate this plot with. The x-axis zoom level of +#' plots within a group is automatically synchronized. +#' @param ... Additional parameters to pass on to [dygraphs::dyOptions]. +#' @importFrom dygraphs renderDygraph dyCSS dyOptions dyLegend dygraph +#' @importFrom xts xts +#' @importFrom RColorBrewer brewer.pal +#' @importFrom magrittr "%>%" +#' @export make_dygraph <- function(data, xlab, ylab, title, legend_name = NULL, use_si = TRUE, expr = NULL, group = NULL, ...) { @@ -94,15 +94,15 @@ dyCSS(css = system.file("custom.css", package = "polloi"))) } -#'@title Select a Colour Conditionally -#'@description select a colour based on the true/false nature of a condition. -#'Uses green as the "true" colour by default, "red" as false, and -#'@param condition a condition to be evaluated to produce a single TRUE or -#' FALSE value. -#'@param true_color the colour used to represent a TRUE result. Green by -#' default. -#'@family Shiny Dashboarding -#'@export +#' @title Select a Colour Conditionally +#' @description select a colour based on the true/false nature of a condition. +#' Uses green as the "true" colour by default, "red" as false, and +#' @param condition a condition to be evaluated to produce a single TRUE or +#' FALSE value. +#' @param true_color the colour used to represent a TRUE result. Green by +#' default. +#' @family Shiny Dashboarding +#' @export cond_color <- function(condition, true_color = "green") { if (is.na(condition)) { return("black") @@ -112,15 +112,15 @@ return(ifelse(condition, true_color, colours[!colours == true_color])) } -#'@title Select an appropriate directional icon -#'@description allows you to select an appropriate directional icon for a -#' change in condition. -#'@param condition a condition to be evaluated to produce a single TRUE/FALSE -#'@param true_direction which direction represents a positive change. "up" by -#'default. -#'@family Shiny Dashboarding -#'@importFrom shiny icon -#'@export +#' @title Select an appropriate directional icon +#' @description allows you to select an appropriate directional icon for a +#' change in condition. +#' @param condition a condition to be evaluated to produce a single TRUE/FALSE +#' @param true_direction which direction represents a positive change. "up" by +#' default. +#' @family Shiny Dashboarding +#' @importFrom shiny icon +#' @export cond_icon <- function(condition, true_direction = "up") { if (true_direction == "up") { diff --git a/R/manipulate.R b/R/manipulate.R index e946648..655d5a4 100644 --- a/R/manipulate.R +++ b/R/manipulate.R @@ -1,12 +1,12 @@ -#'@title Safely retrieve the last N values from an object -#'@description using tail() to get the last sequential values in an object relies -#'on that object being ordered, which it sometimes isn't due to backfilling. \code{safe_tail} -#'retrieves the last N values in a "safe" way, taking the possibility of unordered data into -#'account. -#'@param x an object to tail -#'@param n the number of values to take -#'@param silent whether to produce warnings and messages or not. TRUE by default. -#'@export +#' @title Safely retrieve the last N values from an object +#' @description Using `tail()` to get the last sequential values in an object relies +#' on that object being ordered, which it sometimes isn't due to backfilling. `safe_tail` +#' retrieves the last N values in a "safe" way, taking the possibility of unordered data into +#' account. +#' @param x an object to tail +#' @param n the number of values to take +#' @param silent whether to produce warnings and messages or not. TRUE by default. +#' @export safe_tail <- function(x, n, silent = TRUE) { if (!is.vector(x) && !is.data.frame(x)) { stop("safe_trail() only works with vectors and data frames.") @@ -30,28 +30,28 @@ return(tail(x[order(x[[timestamp_column[1]]]), ], n)) } -#'@title Sample Half an Object -#'@description easily sample the top or bottom half of an object. -#'@param x the object to sample from -#'@param top whether it should be the top (TRUE) or bottom (FALSE) half. -#'Set to TRUE by default. -#'@export +#' @title Sample Half an Object +#' @description easily sample the top or bottom half of an object. +#' @param x the object to sample from +#' @param top whether it should be the top (TRUE) or bottom (FALSE) half. +#' Set to TRUE by default. +#' @export half <- function(x, top = TRUE){ - if(top){ + if (top) { return(head(x, n = length(x)/2)) } return(tail(x, n = length(x)/2)) } -#'@title Subset a data frame by a date range -#'@param x Data frame -#'@param range A vector of length 2 -#'@param from,to A character or Date object to use as upper/lower bound for -#' the subsetting. -#'@param date_col Just in case the date column is named something else other -#' than 'date' -#'@importFrom lubridate ymd -#'@export +#' @title Subset a data frame by a date range +#' @param x Data frame +#' @param range A vector of length 2 +#' @param from,to A character or Date object to use as upper/lower bound for +#' the subsetting. +#' @param date_col Just in case the date column is named something else other +#' than 'date' +#' @importFrom lubridate ymd +#' @export subset_by_date_range <- function(x, range = NULL, from = NULL, to = NULL, date_col = "date") { if (!is.null(range)) { from <- range[1] @@ -74,27 +74,27 @@ return(x[x[[date_col]] >= from & x[[date_col]] <= to, ]) } -#'@title Safely Combine R Objects of Variying Lengths by Columns -#'@description Take a sequence of vector, matrix or data-frame arguments and -#' combine by columns or rows, respectively. -#'@param ... Vectors or matrices. -#'@return A matrix with NAs wherever needed. -#'@references \url{http://r.789695.n4.nabble.com/How-to-join-matrices-of-different-row-length-from-a-list-td3177212.html} -#'@export +#' @title Safely Combine R Objects of Variying Lengths by Columns +#' @description Take a sequence of vector, matrix or data-frame arguments and +#' combine by columns or rows, respectively. +#' @param ... Vectors or matrices. +#' @return A matrix with NAs wherever needed. +#' @references \url{http://r.789695.n4.nabble.com/How-to-join-matrices-of-different-row-length-from-a-list-td3177212.html} +#' @export cbind_fill <- function(...) { nm <- lapply(list(...), as.matrix) n <- max(sapply(nm, nrow)) do.call(cbind, lapply(nm, function (x) rbind(x, matrix(, n-nrow(x), ncol(x))))) } -#'@title Conditionally Select A Dataset -#'@description Like \code{ifelse}, but not awful and usable with -#' \code{data.frames}. -#'@param test an object which can be coerced to logical mode. -#'@param yes_set the dataset to return if \code{test} is true. -#'@param no_set the dataset to return if \code{test} is false. -#'@return The appropriate object. -#'@export +#' @title Conditionally Select A Dataset +#' @description Like `ifelse`, but not awful and usable with +#' `data.frame`s, similar to [dplyr::if_else] +#' @param test an object which can be coerced to logical mode. +#' @param yes_set the dataset to return if `test` is true. +#' @param no_set the dataset to return if `test` is false. +#' @return The appropriate object. +#' @export data_select <- function(test, yes_set, no_set){ if (test) { return(yes_set) diff --git a/R/maths.R b/R/maths.R index fb7eed6..687b794 100644 --- a/R/maths.R +++ b/R/maths.R @@ -1,36 +1,28 @@ -#'@title Calculate a Percentage Change -#' -#'@description calculates a delta between X or Y (or sequential X values) -#'expressed as a percentage. -#' -#'@param x a numeric vector -#' -#'@param y (optionally) an additional numeric vector. If y is not provided, each +#' @title Calculate a Percentage Change +#' @description calculates a delta between X or Y (or sequential X values) +#' expressed as a percentage. +#' @param x a numeric vector +#' @param y (optionally) an additional numeric vector. If y is not provided, each #'value in x will be compared to the subsequent value - if y is, each x value will #'be compared to the equivalent y value. -#' -#'@export +#' @export percent_change <- function(x, y = NULL) { - if(is.null(y)) { + if (is.null(y)) { return(100 * (x - c(NA, x[-length(x)])) / c(NA, x[-length(x)])) } return(100 * (y - x) / x) } -#'@title Convert Numeric Values to use SI suffixes -#' -#'@description takes a numeric vector (1200, 1300, 1400) and converts it to -#'use SI suffixes (1.2K, 1.3K, 1.4k) -#' -#'@param x a vector of numeric or integer values -#' -#'@param round_by how many digits to round the resulting numbers by. -#' -#'@export +#' @title Convert Numeric Values to use SI suffixes +#' @description takes a numeric vector (1200, 1300, 1400) and converts it to +#' use SI suffixes (1.2K, 1.3K, 1.4k) +#' @param x a vector of numeric or integer values +#' @param round_by how many digits to round the resulting numbers by. +#' @export compress <- function(x, round_by = 2) { # by StackOverflow user 'BondedDust' : http://stackoverflow.com/a/28160474 div <- findInterval(as.numeric(gsub("\\,", "", x)), c(1, 1e3, 1e6, 1e9, 1e12) ) - paste(round( as.numeric(gsub("\\,","",x))/10^(3*(div-1)), round_by), + paste(round( as.numeric(gsub("\\,","",x))/10^(3*(div - 1)), round_by), c("","K","M","B","T")[div], sep = "" ) } \ No newline at end of file diff --git a/R/reading.R b/R/reading.R index 8d781de..d2a7f63 100644 --- a/R/reading.R +++ b/R/reading.R @@ -1,15 +1,17 @@ -#'@title Read Datasets from datasets.wikimedia -#'@description Grabs datasets from the public directories at -#'\href{https://datasets.wikimedia.org}{datasets.wikimedia.org} for use in dashboarding. -#' -#'@param path the path to the file, starting from datasets.wikimedia.org/aggregate-datasets/ -#'@param ... Additional arguments to be passed to \code{readr::read_delim} -#' -#'@importFrom readr read_delim -#'@export -read_dataset <- function(path, ...){ - location <- paste0("https://datasets.wikimedia.org/aggregate-datasets/", path, - "?ts=", gsub(x = Sys.time(), pattern = "(-| )", replacement = "")) +#' @title Read Datasets from datasets.wikimedia +#' @description Grabs datasets from the public directories at +#' [WMF Analytics' Datasets](https://analytics.wikimedia.org/datasets/) for +#' use in dashboarding. +#' @param path the path to the file, starting from https://analytics.wikimedia.org/datasets/ +#' @param force_uncached If TRUE, appends a `?ts=...` to URL to force an uncached version +#' @param ... Additional arguments to be passed to [readr::read_delim] +#' @importFrom readr read_delim +#' @export +read_dataset <- function(path, force_uncached = TRUE, ...){ + location <- paste0("https://analytics.wikimedia.org/datasets/", path) + if (force_uncached) { + location <- paste0(location, "?ts=", gsub(x = Sys.time(), pattern = "(-| )", replacement = "")) + } con <- url(location) data <- read_delim(con, delim = "\t", ...) # De-duplicate & return: diff --git a/R/shiny.R b/R/shiny.R index bceef87..150812e 100644 --- a/R/shiny.R +++ b/R/shiny.R @@ -1,8 +1,8 @@ -#'@title Standardised Input Selector for Smoothing -#'@param input_id ID -#'@param label Label -#'@family inputs -#'@export +#' @title Standardised Input Selector for Smoothing +#' @param input_id ID +#' @param label Label +#' @family inputs +#' @export smooth_select <- function(input_id, label = "Smoothing") { return(shiny::selectInput(inputId = input_id, label = label, selectize = TRUE, selected = "global", choices = c("Use Global Setting" = "global", @@ -11,62 +11,62 @@ "Monthly Median" = "month", "Splines" = "gam"))) } -#'@title Standardised Input Selector for Automata Filtering -#'@param input_id ID -#'@param label Label -#'@family inputs -#'@export +#' @title Standardised Input Selector for Automata Filtering +#' @param input_id ID +#' @param label Label +#' @family inputs +#' @export automata_select <- function(input_id, label = "Include automata (e.g. web crawlers)") { return(shiny::checkboxInput(input_id, label = label, value = TRUE)) } -#'@title Standardized Drop-down Selector for Time Frame -#'@param input_id ID -#'@param label Label -#'@return A \code{selectInput} -#'@family inputs -#'@seealso timeframe_daterange "Shiny Dashboarding" -#'@export + +#' @title Standardized Drop-down Selector for Time Frame +#' @param input_id ID +#' @param label Label +#' @return A \code{selectInput} +#' @family inputs +#' @seealso timeframe_daterange "Shiny Dashboarding" +#' @export timeframe_select <- function(input_id, label = "Time Frame") { return(shiny::selectInput(inputId = input_id, label = label, selectize = TRUE, selected = "global", choices = c("Use Global Setting" = "global", "All available data" = "all", "Last 7 days" = "week", "Last 30 days" = "month", "Last 90 days" = "quarter", "Custom" = "custom"))) } -#'@title Standardized Date Range Selector for Time Frame -#'@param select_input_id The ID you used for the corresponding -#' \code{timeframe_select} -#'@param label Label -#'@return A \code{conditionalPanel} containing a \code{dateRangeInput} -#'@family inputs -#'@seealso timeframe_select -#'@export + +#' @title Standardized Date Range Selector for Time Frame +#' @param select_input_id The ID you used for the corresponding +#' [timeframe_select] +#' @param label Label +#' @return A [shiny::conditionalPanel] containing a [shiny::dateRangeInput] +#' @family inputs +#' @export timeframe_daterange <- function(select_input_id, label = "Custom Date Range") { return(shiny::conditionalPanel(paste0("input.", select_input_id," == 'custom'"), shiny::dateRangeInput(paste(select_input_id, "daterange", sep = "_"), label = label, - start = Sys.Date()-11, end = Sys.Date()-1, min = "2015-04-14"))) + start = Sys.Date() - 11, end = Sys.Date() - 1, min = "2015-04-14"))) } -#'@title Get The Time Range -#'@description This figures out the date range based on the four different +#' @title Get The Time Range +#' @description This figures out the date range based on the four different #'inputs: local & global timeframe selections and local & global date range -#'selections. It is used for \code{subset_by_date_range}. -#'@param input_local_timeframe The value of the input corresponding to the +#'selections. It is used for [subset_by_date_range]. +#' @param input_local_timeframe The value of the input corresponding to the #' local timeframe selector. -#'@param input_local_daterange The value of the input corresponding to the +#' @param input_local_daterange The value of the input corresponding to the #' local date range selector. -#'@param input_global_timeframe The value of the input corresponding to the +#' @param input_global_timeframe The value of the input corresponding to the #' global timeframe selector. -#'@param input_global_daterange The value of the input corresponding to the +#' @param input_global_daterange The value of the input corresponding to the #' global date range selector. -#'@return A Date vector of length 2 -#'@examples -#'\dontrun{ -#'time_frame_range(input$timeframe, input$daterange, -#' input$timeframe_global, input$daterange_global) -#'} -#'@seealso \code{\link{subset_by_date_range}} -#'@family Shiny Dashboarding -#'@export +#' @return A Date vector of length 2 +#' @examples +#' \dontrun{ +#' time_frame_range(input$timeframe, input$daterange, +#' input$timeframe_global, input$daterange_global) +#' } +#' @family Shiny Dashboarding +#' @export time_frame_range <- function(input_local_timeframe, input_local_daterange, input_global_timeframe, @@ -87,14 +87,14 @@ custom = input_local_daterange)) } -#'@title Bad Data Value Box -#'@description This is used in cases where something has gone wrong with the -#' data and a value could not be calculated. This ensures the "bad data" value -#' boxes have a consistent look. -#'@param subtitle Subtitle text. -#'@family Shiny Dashboarding -#'@importFrom shinydashboard valueBox -#'@export +#' @title Bad Data Value Box +#' @description This is used in cases where something has gone wrong with the +#' data and a value could not be calculated. This ensures the "bad data" value +#' boxes have a consistent look. +#' @param subtitle Subtitle text. +#' @family Shiny Dashboarding +#' @importFrom shinydashboard valueBox +#' @export na_box <- function(subtitle) { return(valueBox(subtitle = subtitle, value = "NA", color = "red", icon = icon("warning"))) } diff --git a/R/smoothing.R b/R/smoothing.R index a1443d2..3bcaf43 100644 --- a/R/smoothing.R +++ b/R/smoothing.R @@ -1,14 +1,14 @@ -#'@title Switch between global and local smoothing -#'@description We use a lot of smoothing in our reactive graphs, and tend to +#' @title Switch between global and local smoothing +#' @description We use a lot of smoothing in our reactive graphs, and tend to #' offer both global (entire dashboard) and local (tab-specific) smoothing -#' options. \code{smooth_switch} is a simple function to abstract away the +#' options. `smooth_switch` is a simple function to abstract away the #' logic behind determining whether the global or local option should be #' relied on. -#'@param global the input variable for global smoothing. -#'@param local the input variable for local smoothing. -#'@export +#' @param global the input variable for global smoothing. +#' @param local the input variable for local smoothing. +#' @export smooth_switch <- function(global, local){ - if(local == "global"){ + if (local == "global") { return(global) } return(local) diff --git a/R/utils.R b/R/utils.R index 4e5fb27..1a81423 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,12 +1,12 @@ -#'@title Update internal index of language prefixes. -#'@description Scrapes the table off -#' \url{https://en.wikipedia.org/wiki/List_of_Wikipedias} and stores the first -#' three columns containing the language, local language, and the prefix code. -#'@importFrom magrittr "%>%" set_names -#'@importFrom xml2 read_html -#'@importFrom rvest html_nodes html_table -#'@importFrom readr write_csv -#'@export +#' @title Update internal index of language prefixes. +#' @description Scrapes the table off +#' \url{https://en.wikipedia.org/wiki/List_of_Wikipedias} and stores the first +#' three columns containing the language, local language, and the prefix code. +#' @importFrom magrittr "%>%" set_names +#' @importFrom xml2 read_html +#' @importFrom rvest html_nodes html_table +#' @importFrom readr write_csv +#' @export update_prefixes <- function() { if (!requireNamespace("rvest", quietly = TRUE) && !requireNamespace("xml2", quietly = TRUE)) { stop("Requires rvest and xml2 packages to be installed.") diff --git a/README.md b/README.md index f9a14aa..5b5b21a 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,12 @@ Common Files and Functions ========================== -This repository contains files and functions used by all the [Discovery Dashboards](http://discovery.wmflabs.org/) projects. +This repository contains files and functions used by all the [Discovery Dashboards](https://discovery.wmflabs.org/) projects. ## Installation ```R -# install.packages("devtools", repos = "https://cran.rstudio.com/") - +# install.packages("devtools", repos = c(CRAN = "https://cran.rstudio.com/")) devtools::install_git("https://gerrit.wikimedia.org/r/wikimedia/discovery/polloi") ``` diff --git a/inst/extdata/prefixes.csv b/inst/extdata/prefixes.csv index 1b37aa4..0d28a2c 100644 --- a/inst/extdata/prefixes.csv +++ b/inst/extdata/prefixes.csv @@ -28,7 +28,7 @@ Belarusian,беларуская,be Belarusian (Taraškievica),беларуская (тарашкевіца),be-tarask Bengali,বাংলা,bn -Bihari,भोजपुरी,bh +Bhojpuri,भोजपुरी,bh Bishnupriya Manipuri,বিষ্ণুপ্রিয়া মণিপুরী,bpy Bislama,Bislama,bi Bosnian,bosanski,bs @@ -59,6 +59,7 @@ Czech,čeština,cs Danish,dansk,da Divehi,ދިވެހިބަސް,dv +Doteli,डोटेली,dty Dutch,Nederlands,nl Dutch Low Saxon,Nedersaksies,nds-nl Dzongkha,ཇོང་ཁ,dz @@ -85,7 +86,6 @@ Georgian,ქართული,ka German,Deutsch,de Gilaki,گیلکی,glk -Goan Konkani,गोंयची कोंकणी / Gõychi Konknni,gom Gothic,𐌲𐌿𐍄𐌹𐍃𐌺,got Greek,Ελληνικά,el Greenlandic,kalaallisut,kl @@ -134,6 +134,7 @@ Komi,коми,kv Komi-Permyak,Перем Коми,koi Kongo,Kongo,kg +Konkani,गोंयची कोंकणी / Gõychi Konknni,gom Korean,한국어,ko Kuanyama,Kwanyama,kj Kurdish (Kurmanji),Kurdî,ku diff --git a/man/automata_select.Rd b/man/automata_select.Rd index 52fae75..7c40af8 100644 --- a/man/automata_select.Rd +++ b/man/automata_select.Rd @@ -16,4 +16,3 @@ \code{\link{timeframe_daterange}}, \code{\link{timeframe_select}} } - diff --git a/man/cbind_fill.Rd b/man/cbind_fill.Rd index f5a96c7..6a195c0 100644 --- a/man/cbind_fill.Rd +++ b/man/cbind_fill.Rd @@ -14,9 +14,8 @@ } \description{ Take a sequence of vector, matrix or data-frame arguments and - combine by columns or rows, respectively. +combine by columns or rows, respectively. } \references{ \url{http://r.789695.n4.nabble.com/How-to-join-matrices-of-different-row-length-from-a-list-td3177212.html} } - diff --git a/man/check_notify.Rd b/man/check_notify.Rd index 7554fc1..21fcd1a 100644 --- a/man/check_notify.Rd +++ b/man/check_notify.Rd @@ -2,8 +2,8 @@ % Please edit documentation in R/check_notify.R \name{check_notify} \alias{check_notify} -\alias{check_past_week} \alias{check_yesterday} +\alias{check_past_week} \title{Check 'n' Notify} \usage{ check_yesterday(dataset, label) @@ -17,12 +17,11 @@ } \description{ Check a dataset for missing data from the day before and the - past week, and create a \code{notificationItem} if missing data has been - detected. +past week, and create a \code{notificationItem} if missing data has been +detected. } \seealso{ Other Shiny Dashboarding: \code{\link{cond_color}}, \code{\link{cond_icon}}, \code{\link{na_box}}, \code{\link{time_frame_range}} } - diff --git a/man/compress.Rd b/man/compress.Rd index 68ec8a1..edebf0c 100644 --- a/man/compress.Rd +++ b/man/compress.Rd @@ -15,4 +15,3 @@ takes a numeric vector (1200, 1300, 1400) and converts it to use SI suffixes (1.2K, 1.3K, 1.4k) } - diff --git a/man/cond_color.Rd b/man/cond_color.Rd index 5c51ceb..5ff7250 100644 --- a/man/cond_color.Rd +++ b/man/cond_color.Rd @@ -22,4 +22,3 @@ \code{\link{cond_icon}}, \code{\link{na_box}}, \code{\link{time_frame_range}} } - diff --git a/man/cond_icon.Rd b/man/cond_icon.Rd index be1f658..fe82f36 100644 --- a/man/cond_icon.Rd +++ b/man/cond_icon.Rd @@ -14,11 +14,10 @@ } \description{ allows you to select an appropriate directional icon for a - change in condition. +change in condition. } \seealso{ Other Shiny Dashboarding: \code{\link{check_notify}}, \code{\link{cond_color}}, \code{\link{na_box}}, \code{\link{time_frame_range}} } - diff --git a/man/custom_axis_formatter.Rd b/man/custom_axis_formatter.Rd index 817449a..27e28ad 100644 --- a/man/custom_axis_formatter.Rd +++ b/man/custom_axis_formatter.Rd @@ -10,8 +10,8 @@ } \description{ This is a JS date formatter to be used in \code{dyAxis} when - it's desired to have the dates on the axis look like "Monday (8/13)", in - other words: "Day of the week (MM/DD)" +it's desired to have the dates on the axis look like "Monday (8/13)", in +other words: "Day of the week (MM/DD)" } \examples{ \dontrun{ @@ -20,4 +20,3 @@ } } \keyword{datasets} - diff --git a/man/data_select.Rd b/man/data_select.Rd index 4833073..7e91682 100644 --- a/man/data_select.Rd +++ b/man/data_select.Rd @@ -18,6 +18,5 @@ } \description{ Like \code{ifelse}, but not awful and usable with - \code{data.frames}. +\code{data.frame}s, similar to \link[dplyr:if_else]{dplyr::if_else} } - diff --git a/man/get_langproj.Rd b/man/get_langproj.Rd index 28023bb..a764dc6 100644 --- a/man/get_langproj.Rd +++ b/man/get_langproj.Rd @@ -8,16 +8,15 @@ } \description{ Returns a dataset containing all the projects and all possible - language-project combinations for multilingual projects. +language-project combinations for multilingual projects. } \details{ We use a Cartesian product here because we cannot trust the matrix - of languages and projects to be up-to-date, because it is not usually - updated when a new wiki is deployed. The product method ensures that all - the multilingual wikis are correctly captured (provided we have the - latest prefixes) by \code{\link{parse_wikiid}}. +of languages and projects to be up-to-date, because it is not usually +updated when a new wiki is deployed. The product method ensures that all +the multilingual wikis are correctly captured (provided we have the +latest prefixes) by \link{parse_wikiid}. } \seealso{ -\code{\link{get_prefixes}}, \code{\link{get_projects}} +\link{get_prefixes}, \link{get_projects} } - diff --git a/man/get_prefixes.Rd b/man/get_prefixes.Rd index aca4265..f84a0a9 100644 --- a/man/get_prefixes.Rd +++ b/man/get_prefixes.Rd @@ -5,9 +5,9 @@ \title{Wikimedia Language Prefixes} \format{A data frame with 280-some rows and 3 variables: \describe{ - \item{language}{Name of language in English.} - \item{local}{Name of language in local language.} - \item{prefix}{Prefix used -- e.g. 'en' for 'English'.} +\item{language}{Name of language in English.} +\item{local}{Name of language in local language.} +\item{prefix}{Prefix used -- e.g. 'en' for 'English'.} }} \source{ \url{https://meta.wikimedia.org/wiki/Template:Table_of_Wikimedia_projects#Projects_per_language_codes} @@ -17,16 +17,15 @@ } \description{ Returns a dataset containing almost 300 language-prefix pairs - used by multilingual projects (Wikipedia, Wiktionary, Wikibooks, Wikinews, - Wikiquote, Wikisource, Wikiversity, and Wikivoyage). +used by multilingual projects (Wikipedia, Wiktionary, Wikibooks, Wikinews, +Wikiquote, Wikisource, Wikiversity, and Wikivoyage). } \details{ English names of languages come from SIL -- - e.g. \url{http://www-01.sil.org/iso639-3/documentation.asp?id=ady} and are - added to Meta as a Template:Eln -- - e.g. \url{https://meta.wikimedia.org/wiki/Template:Eln_ady} +e.g. \url{http://www-01.sil.org/iso639-3/documentation.asp?id=ady} and are +added to Meta as a Template:Eln -- +e.g. \url{https://meta.wikimedia.org/wiki/Template:Eln_ady} } \seealso{ -\code{\link{update_prefixes}}, \code{\link{get_projects}}, \code{\link{get_langproj}} +\link{update_prefixes}, \link{get_projects}, \link{get_langproj} } - diff --git a/man/get_projects.Rd b/man/get_projects.Rd index 232ff05..159bb82 100644 --- a/man/get_projects.Rd +++ b/man/get_projects.Rd @@ -5,10 +5,10 @@ \title{Wikimedia Projects} \format{A data frame with 280-some rows and 3 variables: \describe{ - \item{wikiid}{The wiki ID used internally.} - \item{project}{Name of the Wikimedia project.} - \item{multilingual}{A boolean indicator whether the project has language - subdomains.} +\item{wikiid}{The wiki ID used internally.} +\item{project}{Name of the Wikimedia project.} +\item{multilingual}{A boolean indicator whether the project has language +subdomains.} }} \source{ \url{https://meta.wikimedia.org/wiki/Table_of_Wikimedia_projects} @@ -18,9 +18,8 @@ } \description{ Returns a dataset containing almost 40 Wikimedia Foundation - projects. +projects. } \seealso{ -\code{\link{update_projects}}, \code{\link{get_prefixes}}, \code{\link{get_langproj}} +\link{update_projects}, \link{get_prefixes}, \link{get_langproj} } - diff --git a/man/half.Rd b/man/half.Rd index 8a1d052..def6975 100644 --- a/man/half.Rd +++ b/man/half.Rd @@ -15,4 +15,3 @@ \description{ easily sample the top or bottom half of an object. } - diff --git a/man/make_dygraph.Rd b/man/make_dygraph.Rd index 3f16127..eb33185 100644 --- a/man/make_dygraph.Rd +++ b/man/make_dygraph.Rd @@ -8,7 +8,7 @@ expr = NULL, group = NULL, ...) } \arguments{ -\item{data}{a data.frame reformatted to be XTS-able.} +\item{data}{a \code{data.frame} reformatted to be XTS-able.} \item{xlab}{the label to use for the dygraph's x-axis.} @@ -28,13 +28,12 @@ \item{group}{Group to associate this plot with. The x-axis zoom level of plots within a group is automatically synchronized.} -\item{...}{Additional parameters to pass on to \code{dyOptions}.} +\item{...}{Additional parameters to pass on to \link[dygraphs:dyOptions]{dygraphs::dyOptions}.} } \description{ Construct a dygraph using the custom formatting Wikimedia - dashboards use as standard. This is nothing special - a standard dygraph - with a bit of custom CSS shipped with the package - but it's surrounded by - code that allows the function to turn all our usual data.frame formats - into XTS objects. +dashboards use as standard. This is nothing special - a standard dygraph +with a bit of custom CSS shipped with the package - but it's surrounded by +code that allows the function to turn all our usual \code{data.frame} formats +into \link[xts:xts]{xts::xts} objects. } - diff --git a/man/na_box.Rd b/man/na_box.Rd index 7dc9a96..58e61d6 100644 --- a/man/na_box.Rd +++ b/man/na_box.Rd @@ -11,12 +11,11 @@ } \description{ This is used in cases where something has gone wrong with the - data and a value could not be calculated. This ensures the "bad data" value - boxes have a consistent look. +data and a value could not be calculated. This ensures the "bad data" value +boxes have a consistent look. } \seealso{ Other Shiny Dashboarding: \code{\link{check_notify}}, \code{\link{cond_color}}, \code{\link{cond_icon}}, \code{\link{time_frame_range}} } - diff --git a/man/parse_wikiid.Rd b/man/parse_wikiid.Rd index de67d47..c780236 100644 --- a/man/parse_wikiid.Rd +++ b/man/parse_wikiid.Rd @@ -14,6 +14,5 @@ } \description{ Uses the internal index of languages, prefixes, wikis, and - projects to parse a wikiid into a language-project tuple. +projects to parse a wikiid into a language-project tuple. } - diff --git a/man/percent_change.Rd b/man/percent_change.Rd index d7c7e91..555ba22 100644 --- a/man/percent_change.Rd +++ b/man/percent_change.Rd @@ -17,4 +17,3 @@ calculates a delta between X or Y (or sequential X values) expressed as a percentage. } - diff --git a/man/read_dataset.Rd b/man/read_dataset.Rd index 70e95ca..5cdee6d 100644 --- a/man/read_dataset.Rd +++ b/man/read_dataset.Rd @@ -4,15 +4,17 @@ \alias{read_dataset} \title{Read Datasets from datasets.wikimedia} \usage{ -read_dataset(path, ...) +read_dataset(path, force_uncached = TRUE, ...) } \arguments{ -\item{path}{the path to the file, starting from datasets.wikimedia.org/aggregate-datasets/} +\item{path}{the path to the file, starting from https://analytics.wikimedia.org/datasets/} -\item{...}{Additional arguments to be passed to \code{readr::read_delim}} +\item{force_uncached}{If TRUE, appends a \code{?ts=...} to URL to force an uncached version} + +\item{...}{Additional arguments to be passed to \link[readr:read_delim]{readr::read_delim}} } \description{ Grabs datasets from the public directories at -\href{https://datasets.wikimedia.org}{datasets.wikimedia.org} for use in dashboarding. +\href{https://analytics.wikimedia.org/datasets/}{WMF Analytics' Datasets} for +use in dashboarding. } - diff --git a/man/safe_tail.Rd b/man/safe_tail.Rd index 4d76bb0..dd6fa2f 100644 --- a/man/safe_tail.Rd +++ b/man/safe_tail.Rd @@ -14,9 +14,8 @@ \item{silent}{whether to produce warnings and messages or not. TRUE by default.} } \description{ -using tail() to get the last sequential values in an object relies +Using \code{tail()} to get the last sequential values in an object relies on that object being ordered, which it sometimes isn't due to backfilling. \code{safe_tail} retrieves the last N values in a "safe" way, taking the possibility of unordered data into account. } - diff --git a/man/smart_palette.Rd b/man/smart_palette.Rd index 7e005ff..4196784 100644 --- a/man/smart_palette.Rd +++ b/man/smart_palette.Rd @@ -14,8 +14,7 @@ } \description{ Picks between 3 different color palettes based on number of - categories to visualize. For <13 categories, uses Set1, Paired, & Set3 - from RColorBrewer. For More than 12 categories, builds a HCL color - space-based palette. +categories to visualize. For <13 categories, uses Set1, Paired, & Set3 +from RColorBrewer. For More than 12 categories, builds a HCL color +space-based palette. } - diff --git a/man/smooth_select.Rd b/man/smooth_select.Rd index 02a8ea1..c988582 100644 --- a/man/smooth_select.Rd +++ b/man/smooth_select.Rd @@ -16,4 +16,3 @@ \code{\link{timeframe_daterange}}, \code{\link{timeframe_select}} } - diff --git a/man/smooth_switch.Rd b/man/smooth_switch.Rd index 234523d..ef7f442 100644 --- a/man/smooth_switch.Rd +++ b/man/smooth_switch.Rd @@ -13,9 +13,8 @@ } \description{ We use a lot of smoothing in our reactive graphs, and tend to - offer both global (entire dashboard) and local (tab-specific) smoothing - options. \code{smooth_switch} is a simple function to abstract away the - logic behind determining whether the global or local option should be - relied on. +offer both global (entire dashboard) and local (tab-specific) smoothing +options. \code{smooth_switch} is a simple function to abstract away the +logic behind determining whether the global or local option should be +relied on. } - diff --git a/man/smoother.Rd b/man/smoother.Rd index 0f9dac7..562f763 100644 --- a/man/smoother.Rd +++ b/man/smoother.Rd @@ -18,4 +18,3 @@ Takes an untidy (read: dygraph-appropriate) dataset and adds columns for each variable consisting of the smoothed, averaged mean. } - diff --git a/man/subset_by_date_range.Rd b/man/subset_by_date_range.Rd index ceddf34..74ed9ab 100644 --- a/man/subset_by_date_range.Rd +++ b/man/subset_by_date_range.Rd @@ -18,4 +18,3 @@ \item{date_col}{Just in case the date column is named something else other than 'date'} } - diff --git a/man/time_frame_range.Rd b/man/time_frame_range.Rd index 1b1635d..53e09da 100644 --- a/man/time_frame_range.Rd +++ b/man/time_frame_range.Rd @@ -26,19 +26,16 @@ \description{ This figures out the date range based on the four different inputs: local & global timeframe selections and local & global date range -selections. It is used for \code{subset_by_date_range}. +selections. It is used for \link{subset_by_date_range}. } \examples{ \dontrun{ time_frame_range(input$timeframe, input$daterange, - input$timeframe_global, input$daterange_global) + input$timeframe_global, input$daterange_global) } } \seealso{ -\code{\link{subset_by_date_range}} - Other Shiny Dashboarding: \code{\link{check_notify}}, \code{\link{cond_color}}, \code{\link{cond_icon}}, \code{\link{na_box}} } - diff --git a/man/timeframe_daterange.Rd b/man/timeframe_daterange.Rd index 5b7864e..2816ac5 100644 --- a/man/timeframe_daterange.Rd +++ b/man/timeframe_daterange.Rd @@ -8,18 +8,15 @@ } \arguments{ \item{select_input_id}{The ID you used for the corresponding -\code{timeframe_select}} +\link{timeframe_select}} \item{label}{Label} } \value{ -A \code{conditionalPanel} containing a \code{dateRangeInput} +A \link[shiny:conditionalPanel]{shiny::conditionalPanel} containing a \link[shiny:dateRangeInput]{shiny::dateRangeInput} } \seealso{ -timeframe_select - Other inputs: \code{\link{automata_select}}, \code{\link{smooth_select}}, \code{\link{timeframe_select}} } - diff --git a/man/timeframe_select.Rd b/man/timeframe_select.Rd index 1addfdc..b3f9cc7 100644 --- a/man/timeframe_select.Rd +++ b/man/timeframe_select.Rd @@ -21,4 +21,3 @@ \code{\link{smooth_select}}, \code{\link{timeframe_daterange}} } - diff --git a/man/update_prefixes.Rd b/man/update_prefixes.Rd index 95e42be..ec79daa 100644 --- a/man/update_prefixes.Rd +++ b/man/update_prefixes.Rd @@ -8,7 +8,6 @@ } \description{ Scrapes the table off - \url{https://en.wikipedia.org/wiki/List_of_Wikipedias} and stores the first - three columns containing the language, local language, and the prefix code. +\url{https://en.wikipedia.org/wiki/List_of_Wikipedias} and stores the first +three columns containing the language, local language, and the prefix code. } - diff --git a/man/update_projects.Rd b/man/update_projects.Rd index 01843f9..26c3a2f 100644 --- a/man/update_projects.Rd +++ b/man/update_projects.Rd @@ -8,6 +8,5 @@ } \description{ Updates the internal list of Wikimedia projects from the package - repository to avoid having to reinstall the package from source. +repository to avoid having to reinstall the package from source. } - -- To view, visit https://gerrit.wikimedia.org/r/356470 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I34172c3198624425f6dfe55358d79e964791137a Gerrit-PatchSet: 1 Gerrit-Project: wikimedia/discovery/polloi Gerrit-Branch: master Gerrit-Owner: Bearloga <mpo...@wikimedia.org> Gerrit-Reviewer: Bearloga <mpo...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits