Compare commits
16
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a02e72e618 | ||
|
|
4a2cd9e1dd | ||
|
|
f50290ba40 | ||
|
|
8b8dd50de3 | ||
|
|
34cc4a5c1a | ||
|
|
6f4ccc0d4e | ||
|
|
920098e18d | ||
|
|
c004628682 | ||
|
|
f2dca18041 | ||
|
|
72afbaeefa | ||
|
|
d061c4e802 | ||
|
|
904ca1dbc8 | ||
|
|
1550c2cb5b | ||
|
|
b44a254029 | ||
|
|
399cb7101d | ||
|
|
38a7e2f242 |
@@ -2,3 +2,5 @@
|
|||||||
^\.Rproj\.user$
|
^\.Rproj\.user$
|
||||||
^\.github$
|
^\.github$
|
||||||
^README\.Rmd$
|
^README\.Rmd$
|
||||||
|
^Makefile$
|
||||||
|
^Jenkinsfile$
|
||||||
|
|||||||
+1
-1
@@ -21,4 +21,4 @@ Encoding: UTF-8
|
|||||||
LazyData: true
|
LazyData: true
|
||||||
Suggests:
|
Suggests:
|
||||||
testthat
|
testthat
|
||||||
RoxygenNote: 7.1.0
|
RoxygenNote: 7.2.1
|
||||||
|
|||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
# [Choice] R version: 4, 4.2, 4.1, 4.0
|
||||||
|
ARG VARIANT=4.2
|
||||||
|
# [Choice] Base image. Minimal (r-ver), tidyverse installed (tidyverse), or full image (binder): rocker/r-ver, rocker/tidyverse, rocker/binder
|
||||||
|
ARG BASE_IMAGE=rocker/r-ver
|
||||||
|
FROM ${BASE_IMAGE}:${VARIANT}
|
||||||
|
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
|
sudo \
|
||||||
|
libcurl4-gnutls-dev \
|
||||||
|
libxml2-dev \
|
||||||
|
libcairo2-dev \
|
||||||
|
libxt-dev \
|
||||||
|
libjpeg-dev \
|
||||||
|
libpng-dev \
|
||||||
|
openjdk-11-jdk \
|
||||||
|
libssl-dev \
|
||||||
|
libssh2-1-dev \
|
||||||
|
&& rm -rf /var/lib/apt/lists/* \
|
||||||
|
&& mkdir -p /var/lib/shiny-server/bookmarks/shiny
|
||||||
|
|
||||||
|
RUN install2.r ggplot2 jpeg png stringr gridExtra grid testthat
|
||||||
Vendored
+53
@@ -0,0 +1,53 @@
|
|||||||
|
pipeline {
|
||||||
|
agent {
|
||||||
|
dockerfile true
|
||||||
|
}
|
||||||
|
stages {
|
||||||
|
stage('Docker setup') {
|
||||||
|
steps {
|
||||||
|
sh '''
|
||||||
|
R --version
|
||||||
|
java --version
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
stage('Build and test') {
|
||||||
|
stages {
|
||||||
|
stage("Build package") {
|
||||||
|
steps {
|
||||||
|
sh '''
|
||||||
|
R CMD build .
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage('Check') {
|
||||||
|
steps {
|
||||||
|
sh '''
|
||||||
|
R CMD check --no-manual civilytics_0.1.0.tar.gz
|
||||||
|
'''
|
||||||
|
|
||||||
|
sh '''
|
||||||
|
R CMD INSTALL civilytics_0.1.0.tar.gz
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage('testthat'){
|
||||||
|
steps {
|
||||||
|
sh '''
|
||||||
|
R -e 'testthat::test_local(".")'
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage('Clean') {
|
||||||
|
steps {
|
||||||
|
|
||||||
|
sh '''
|
||||||
|
@rm -rf civilytics_0.1.0.tar.gz civilytics.Rcheck
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
# h/t to @jimhester and @yihui for this parse block:
|
||||||
|
# https://github.com/yihui/knitr/blob/dc5ead7bcfc0ebd2789fe99c527c7d91afb3de4a/Makefile#L1-L4
|
||||||
|
# Note the portability change as suggested in the manual:
|
||||||
|
# https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Writing-portable-packages
|
||||||
|
PKGNAME = `sed -n "s/Package: *\([^ ]*\)/\1/p" DESCRIPTION`
|
||||||
|
PKGVERS = `sed -n "s/Version: *\([^ ]*\)/\1/p" DESCRIPTION`
|
||||||
|
|
||||||
|
|
||||||
|
all: check
|
||||||
|
|
||||||
|
build: install_deps
|
||||||
|
R CMD build .
|
||||||
|
|
||||||
|
check: build
|
||||||
|
R CMD check --no-manual $(PKGNAME)_$(PKGVERS).tar.gz
|
||||||
|
|
||||||
|
install_deps:
|
||||||
|
Rscript \
|
||||||
|
-e 'if (!requireNamespace("remotes")) install.packages("remotes")' \
|
||||||
|
-e 'remotes::install_deps(dependencies = TRUE)'
|
||||||
|
|
||||||
|
install: build
|
||||||
|
R CMD INSTALL $(PKGNAME)_$(PKGVERS).tar.gz
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@rm -rf $(PKGNAME)_$(PKGVERS).tar.gz $(PKGNAME).Rcheck
|
||||||
@@ -8,6 +8,7 @@ export(countNA)
|
|||||||
export(dbSafeNames)
|
export(dbSafeNames)
|
||||||
export(findDots)
|
export(findDots)
|
||||||
export(get_png)
|
export(get_png)
|
||||||
|
export(grade_level_to_num)
|
||||||
export(has_caption)
|
export(has_caption)
|
||||||
export(make_logo_grob)
|
export(make_logo_grob)
|
||||||
export(measure_caption)
|
export(measure_caption)
|
||||||
@@ -16,8 +17,10 @@ export(nvals)
|
|||||||
export(plot_jpeg)
|
export(plot_jpeg)
|
||||||
export(pretty_count)
|
export(pretty_count)
|
||||||
export(pretty_per)
|
export(pretty_per)
|
||||||
|
export(race_short_names)
|
||||||
export(safe_max)
|
export(safe_max)
|
||||||
export(simpleCap)
|
export(simpleCap)
|
||||||
|
export(star_subs)
|
||||||
export(theme_civilytics)
|
export(theme_civilytics)
|
||||||
import(ggplot2)
|
import(ggplot2)
|
||||||
importFrom(ggplot2,theme)
|
importFrom(ggplot2,theme)
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ add_logo <- function(plot, logo, margin_param = NULL) {
|
|||||||
#' @export
|
#' @export
|
||||||
#'
|
#'
|
||||||
#' @examples
|
#' @examples
|
||||||
#' p1 <- qplot(mpg, wt, data = mtcars)
|
#' p1 <- ggplot2::qplot(mpg, wt, data = mtcars)
|
||||||
#' measure_caption(p1) # Should equal 1 since no caption is required
|
#' measure_caption(p1) # Should equal 1 since no caption is required
|
||||||
measure_caption <- function(gg) {
|
measure_caption <- function(gg) {
|
||||||
if (has_caption(gg)) {
|
if (has_caption(gg)) {
|
||||||
|
|||||||
@@ -73,3 +73,75 @@ pretty_count <- function(x) {
|
|||||||
x <- prettyNum(x, big.mark = ",")
|
x <- prettyNum(x, big.mark = ",")
|
||||||
return(x)
|
return(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#' Unsuppress data using sampling
|
||||||
|
#'
|
||||||
|
#' @param x
|
||||||
|
#' @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
|
||||||
|
#' @return a numeric vector with no characters representing suppressed values
|
||||||
|
#' @export
|
||||||
|
#'
|
||||||
|
#' @examples
|
||||||
|
#' suppr_data <- c("2", "8", "*", "*", "7", "9", "100")
|
||||||
|
#' star_subs(suppr_data, zeros = 1, max_value = 10)
|
||||||
|
#' star_subs(suppr_data, zeros = 1, max_value = 200)
|
||||||
|
star_subs <- function(x, replace_char = "*",
|
||||||
|
zeros = 15, max_value = 20) {
|
||||||
|
x[x == "*"] <- sample(c(rep("0", zeros), as.character(0:max_value)),
|
||||||
|
sum(x==replace_char), replace = TRUE)
|
||||||
|
x <- as.numeric(x)
|
||||||
|
return(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#' Recode grade level from character to numeric
|
||||||
|
#'
|
||||||
|
#' @param x character description of grade levels from NCES style data
|
||||||
|
#'
|
||||||
|
#' @return
|
||||||
|
#' @export
|
||||||
|
#'
|
||||||
|
#' @examples
|
||||||
|
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)
|
||||||
|
x[x %in% c("KG", "Kindergarten")] <- "0"
|
||||||
|
x[x %in% c("Pre-K", "Pre-k", "Preschool", "Pre-Kindergarten")] <- "-1"
|
||||||
|
x[x %in% c("Adult", "Adult Education")] <- "13"
|
||||||
|
y <- as.numeric(x)
|
||||||
|
return(y)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#' Recode NCES race categories to shorter names
|
||||||
|
#'
|
||||||
|
#' @param x a character vector with NCES race codes, often from Urban Institute
|
||||||
|
#'
|
||||||
|
#' @return
|
||||||
|
#' @export
|
||||||
|
#'
|
||||||
|
#' @examples
|
||||||
|
race_short_names <- function(x) {
|
||||||
|
x <- as.character(x)
|
||||||
|
x[x %in% c("Black", "Black Or African American", "Black or African American",
|
||||||
|
"African American")] <- "black"
|
||||||
|
x[x %in% c("Hispanic", "Hispanic Or Latino", "Hispanic or Latino")] <-
|
||||||
|
"hisp_lat"
|
||||||
|
x[x %in% c("White", "white", "White and Not Hispanic")] <- "white"
|
||||||
|
x[x %in% c("Asian", "Asian American")] <- "asian"
|
||||||
|
x[x %in% c("Two Or More Races", "Two or More Races")] <- "two_or_more"
|
||||||
|
x[x %in% c("Native Hawaiian Or Other Pacific Islander",
|
||||||
|
"Native Hawaiian or Other Pacific Islander",
|
||||||
|
"Native Hawaiian Pacific Islander")] <- "native_haw"
|
||||||
|
x[x %in% c("American Indian", "American Indian Or Alaska Native",
|
||||||
|
"American Indian or Alaska Native", "American Indian or Native Alaskan")] <- "amind"
|
||||||
|
x[x %in% c("Not Reported")] <- "other"
|
||||||
|
return(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -12,9 +12,6 @@ add_logo(plot, logo, margin_param = NULL)
|
|||||||
\item{logo}{a logo grob created by make_logo_grob()}
|
\item{logo}{a logo grob created by make_logo_grob()}
|
||||||
|
|
||||||
\item{margin_param}{a numeric specifying what margin to add or subtract to align the logo}
|
\item{margin_param}{a numeric specifying what margin to add or subtract to align the logo}
|
||||||
}
|
|
||||||
\value{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
\description{
|
\description{
|
||||||
Add a logo to a ggplot2 object
|
Add a logo to a ggplot2 object
|
||||||
|
|||||||
@@ -16,9 +16,6 @@ add_logo_ga(plot_list, logo, nrow = 1, widths = NULL, margin_param = NULL)
|
|||||||
\item{widths}{an optional vector the same length as plot_list with the widths for each plot}
|
\item{widths}{an optional vector the same length as plot_list with the widths for each plot}
|
||||||
|
|
||||||
\item{margin_param}{a number giving the adjustment up or down to help manually align logo and captions}
|
\item{margin_param}{a number giving the adjustment up or down to help manually align logo and captions}
|
||||||
}
|
|
||||||
\value{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
\description{
|
\description{
|
||||||
Add a logo to a ggplot2 object
|
Add a logo to a ggplot2 object
|
||||||
|
|||||||
@@ -8,9 +8,6 @@ countDots(x)
|
|||||||
}
|
}
|
||||||
\arguments{
|
\arguments{
|
||||||
\item{x}{a character vector}
|
\item{x}{a character vector}
|
||||||
}
|
|
||||||
\value{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
\description{
|
\description{
|
||||||
Count the number of single period entries in a vector
|
Count the number of single period entries in a vector
|
||||||
|
|||||||
@@ -8,13 +8,7 @@ get_png(filename)
|
|||||||
}
|
}
|
||||||
\arguments{
|
\arguments{
|
||||||
\item{filename}{a character with file path to a png file}
|
\item{filename}{a character with file path to a png file}
|
||||||
}
|
|
||||||
\value{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
\description{
|
\description{
|
||||||
Plot a PNG file as a rasterGrob for inclusion in ggplot2
|
Plot a PNG file as a rasterGrob for inclusion in ggplot2
|
||||||
}
|
}
|
||||||
\examples{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
% Generated by roxygen2: do not edit by hand
|
||||||
|
% Please edit documentation in R/utils.R
|
||||||
|
\name{grade_level_to_num}
|
||||||
|
\alias{grade_level_to_num}
|
||||||
|
\title{Recode grade level from character to numeric}
|
||||||
|
\usage{
|
||||||
|
grade_level_to_num(x)
|
||||||
|
}
|
||||||
|
\arguments{
|
||||||
|
\item{x}{character description of grade levels from NCES style data}
|
||||||
|
}
|
||||||
|
\description{
|
||||||
|
Recode grade level from character to numeric
|
||||||
|
}
|
||||||
@@ -17,6 +17,6 @@ the caption
|
|||||||
Measure a ggplot2 object caption
|
Measure a ggplot2 object caption
|
||||||
}
|
}
|
||||||
\examples{
|
\examples{
|
||||||
p1 <- qplot(mpg, wt, data = mtcars)
|
p1 <- ggplot2::qplot(mpg, wt, data = mtcars)
|
||||||
measure_caption(p1) # Should equal 1 since no caption is required
|
measure_caption(p1) # Should equal 1 since no caption is required
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
% Generated by roxygen2: do not edit by hand
|
||||||
|
% Please edit documentation in R/utils.R
|
||||||
|
\name{race_short_names}
|
||||||
|
\alias{race_short_names}
|
||||||
|
\title{Recode NCES race categories to shorter names}
|
||||||
|
\usage{
|
||||||
|
race_short_names(x)
|
||||||
|
}
|
||||||
|
\arguments{
|
||||||
|
\item{x}{a character vector with NCES race codes, often from Urban Institute}
|
||||||
|
}
|
||||||
|
\description{
|
||||||
|
Recode NCES race categories to shorter names
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
% Generated by roxygen2: do not edit by hand
|
||||||
|
% Please edit documentation in R/utils.R
|
||||||
|
\name{star_subs}
|
||||||
|
\alias{star_subs}
|
||||||
|
\title{Unsuppress data using sampling}
|
||||||
|
\usage{
|
||||||
|
star_subs(x, replace_char = "*", zeros = 15, max_value = 20)
|
||||||
|
}
|
||||||
|
\arguments{
|
||||||
|
\item{replace_char}{the character you want to replace in the vector}
|
||||||
|
|
||||||
|
\item{zeros}{the number of zeroes to oversample when replacing replace_char}
|
||||||
|
|
||||||
|
\item{max_value}{the numeric maximum value the replacement for the "*" can be}
|
||||||
|
}
|
||||||
|
\value{
|
||||||
|
a numeric vector with no characters representing suppressed values
|
||||||
|
}
|
||||||
|
\description{
|
||||||
|
Unsuppress data using sampling
|
||||||
|
}
|
||||||
|
\examples{
|
||||||
|
suppr_data <- c("2", "8", "*", "*", "7", "9", "100")
|
||||||
|
star_subs(suppr_data, zeros = 1, max_value = 10)
|
||||||
|
star_subs(suppr_data, zeros = 1, max_value = 200)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user