From 91dad765260ee88e137b1586e76a2183f09e9a22 Mon Sep 17 00:00:00 2001 From: Jared Knowles Date: Sun, 16 Oct 2022 19:30:05 -0400 Subject: [PATCH] cleanup tests and build --- .Rbuildignore | 1 + R/db.R | 7 +------ R/logo.R | 13 ++++--------- R/utils.R | 8 +++++--- man/add_logo.Rd | 3 +++ man/add_logo_ga.Rd | 3 +++ man/countDots.Rd | 3 +++ man/get_png.Rd | 3 +++ man/grade_level_to_num.Rd | 6 ++++++ man/plot_jpeg.Rd | 2 +- man/race_short_names.Rd | 6 ++++++ man/star_subs.Rd | 2 ++ 12 files changed, 38 insertions(+), 19 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index 9388454..3d42b79 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -4,3 +4,4 @@ ^README\.Rmd$ ^Makefile$ ^Jenkinsfile$ +^Dockerfile$ diff --git a/R/db.R b/R/db.R index 4f107e6..637ebd9 100644 --- a/R/db.R +++ b/R/db.R @@ -37,8 +37,6 @@ countCleanr <- function(x){ #' #' @return the names of columns in the dataframe with one or more entries equal to "." #' @export -#' -#' @examples findDots <- function(data){ return(names(data)[lapply(data, countDots) > 0]) @@ -49,9 +47,8 @@ findDots <- function(data){ #' @param x a character vector #' #' @return +#' An integer counting the number of "." occurences in a vector #' @export -#' -#' @examples countDots <- function(x){ len <- length(x[x == "." & !is.na(x)]) totlen <- length(x) @@ -65,8 +62,6 @@ countDots <- function(x){ #' #' @return a vector the same length as the input vector with clean names #' @export -#' -#' @examples dbSafeNames <- function(names) { names = gsub('[^a-z0-9]+','_',tolower(names)) names = make.names(names, unique = TRUE, allow_ = TRUE) diff --git a/R/logo.R b/R/logo.R index c549c1e..d44fbd8 100644 --- a/R/logo.R +++ b/R/logo.R @@ -9,7 +9,7 @@ #' @importFrom jpeg readJPEG #' @importFrom graphics rasterImage #' @examples -#' img <- system.file("img","Civilytics Consulting Logo.jpg",package="civilytics") +#' img <- system.file("img","civilytics_logo.jpg",package="civilytics") #' plot_jpeg(img) plot_jpeg <- function(path, add=FALSE, upscale = TRUE) { @@ -30,13 +30,10 @@ plot_jpeg <- function(path, add=FALSE, upscale = TRUE) #' #' @param filename a character with file path to a png file #' -#' @return +#' @return a plotted rasteGrob of a png image #' @export #' @importFrom png readPNG #' @importFrom grid rasterGrob -#' -#' @examples -#' get_png <- function(filename) { grid::rasterGrob(png::readPNG(filename), interpolate = TRUE) } @@ -48,12 +45,10 @@ get_png <- function(filename) { #' @param logo a logo grob created by make_logo_grob() #' @param margin_param a numeric specifying what margin to add or subtract to align the logo #' -#' @return +#' @return a grob with a logo attached to it ready to plot #' @importFrom ggplot2 theme #' @importFrom gridExtra arrangeGrob #' @export -#' -#' @examples add_logo <- function(plot, logo, margin_param = NULL) { if(has_caption(plot)) { # convert the caption size to a negative number and on the "pt" scale @@ -118,7 +113,7 @@ has_caption <- function(gg) { #' @param widths an optional vector the same length as plot_list with the widths for each plot #' @param margin_param a number giving the adjustment up or down to help manually align logo and captions #' -#' @return +#' @return a grid object #' @note The resulting object needs to be drawn to the screen using grid.draw() #' @importFrom gridExtra arrangeGrob #' @importFrom ggplot2 theme diff --git a/R/utils.R b/R/utils.R index f56d67a..674c779 100644 --- a/R/utils.R +++ b/R/utils.R @@ -78,7 +78,7 @@ pretty_count <- function(x) { #' Unsuppress data using sampling #' -#' @param x +#' @param x a vector #' @param replace_char the character you want to replace in the vector #' @param zeros the number of zeroes to oversample when replacing replace_char #' @param max_value the numeric maximum value the replacement for the "*" can be @@ -103,10 +103,11 @@ star_subs <- function(x, replace_char = "*", #' #' @param x character description of grade levels from NCES style data #' -#' @return +#' @return a numeric vector #' @export #' #' @examples +#' grade_level_to_num(c("KG", "Pre-K", "12", "10", "09")) grade_level_to_num <- function(x) { # Cannot generate new levels if it is a factor so we coerce to character first x <- as.character(x) @@ -122,10 +123,11 @@ grade_level_to_num <- function(x) { #' #' @param x a character vector with NCES race codes, often from Urban Institute #' -#' @return +#' @return recoded race categories following NCES race codes #' @export #' #' @examples +#' race_short_names(c("Black", "Hispanic Or Latino", "Two Or More Races")) race_short_names <- function(x) { x <- as.character(x) x[x %in% c("Black", "Black Or African American", "Black or African American", diff --git a/man/add_logo.Rd b/man/add_logo.Rd index e3e86bc..f698eb7 100644 --- a/man/add_logo.Rd +++ b/man/add_logo.Rd @@ -13,6 +13,9 @@ add_logo(plot, logo, margin_param = NULL) \item{margin_param}{a numeric specifying what margin to add or subtract to align the logo} } +\value{ +a grob with a logo attached to it ready to plot +} \description{ Add a logo to a ggplot2 object } diff --git a/man/add_logo_ga.Rd b/man/add_logo_ga.Rd index 79d1157..fedb5c5 100644 --- a/man/add_logo_ga.Rd +++ b/man/add_logo_ga.Rd @@ -17,6 +17,9 @@ add_logo_ga(plot_list, logo, nrow = 1, widths = NULL, margin_param = NULL) \item{margin_param}{a number giving the adjustment up or down to help manually align logo and captions} } +\value{ +a grid object +} \description{ Add a logo to a ggplot2 object } diff --git a/man/countDots.Rd b/man/countDots.Rd index 71c99d9..7b81d0e 100644 --- a/man/countDots.Rd +++ b/man/countDots.Rd @@ -9,6 +9,9 @@ countDots(x) \arguments{ \item{x}{a character vector} } +\value{ +An integer counting the number of "." occurences in a vector +} \description{ Count the number of single period entries in a vector } diff --git a/man/get_png.Rd b/man/get_png.Rd index f5edd11..97988bc 100644 --- a/man/get_png.Rd +++ b/man/get_png.Rd @@ -9,6 +9,9 @@ get_png(filename) \arguments{ \item{filename}{a character with file path to a png file} } +\value{ +a plotted rasteGrob of a png image +} \description{ Plot a PNG file as a rasterGrob for inclusion in ggplot2 } diff --git a/man/grade_level_to_num.Rd b/man/grade_level_to_num.Rd index fd6a9bc..03a9990 100644 --- a/man/grade_level_to_num.Rd +++ b/man/grade_level_to_num.Rd @@ -9,6 +9,12 @@ grade_level_to_num(x) \arguments{ \item{x}{character description of grade levels from NCES style data} } +\value{ +a numeric vector +} \description{ Recode grade level from character to numeric } +\examples{ +grade_level_to_num(c("KG", "Pre-K", "12", "10", "09")) +} diff --git a/man/plot_jpeg.Rd b/man/plot_jpeg.Rd index 582f0c6..5ad1306 100644 --- a/man/plot_jpeg.Rd +++ b/man/plot_jpeg.Rd @@ -21,6 +21,6 @@ a rasterImage Plot a jpeg image as a raster } \examples{ -img <- system.file("img","Civilytics Consulting Logo.jpg",package="civilytics") +img <- system.file("img","civilytics_logo.jpg",package="civilytics") plot_jpeg(img) } diff --git a/man/race_short_names.Rd b/man/race_short_names.Rd index c7e5eab..6215020 100644 --- a/man/race_short_names.Rd +++ b/man/race_short_names.Rd @@ -9,6 +9,12 @@ race_short_names(x) \arguments{ \item{x}{a character vector with NCES race codes, often from Urban Institute} } +\value{ +recoded race categories following NCES race codes +} \description{ Recode NCES race categories to shorter names } +\examples{ +race_short_names(c("Black", "Hispanic Or Latino", "Two Or More Races")) +} diff --git a/man/star_subs.Rd b/man/star_subs.Rd index abb0b27..da8f91d 100644 --- a/man/star_subs.Rd +++ b/man/star_subs.Rd @@ -7,6 +7,8 @@ star_subs(x, replace_char = "*", zeros = 15, max_value = 20) } \arguments{ +\item{x}{a vector} + \item{replace_char}{the character you want to replace in the vector} \item{zeros}{the number of zeroes to oversample when replacing replace_char}