Compare commits
16
Commits
fisc
..
91dad76526
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
91dad76526 | ||
|
|
a02e72e618 | ||
|
|
4a2cd9e1dd | ||
|
|
f50290ba40 | ||
|
|
8b8dd50de3 | ||
|
|
34cc4a5c1a | ||
|
|
6f4ccc0d4e | ||
|
|
920098e18d | ||
|
|
c004628682 | ||
|
|
f2dca18041 | ||
|
|
72afbaeefa | ||
|
|
d061c4e802 | ||
|
|
904ca1dbc8 | ||
|
|
1550c2cb5b | ||
|
|
b44a254029 | ||
|
|
399cb7101d |
@@ -2,3 +2,6 @@
|
|||||||
^\.Rproj\.user$
|
^\.Rproj\.user$
|
||||||
^\.github$
|
^\.github$
|
||||||
^README\.Rmd$
|
^README\.Rmd$
|
||||||
|
^Makefile$
|
||||||
|
^Jenkinsfile$
|
||||||
|
^Dockerfile$
|
||||||
|
|||||||
+24
-24
@@ -1,24 +1,24 @@
|
|||||||
Package: civilytics
|
Package: civilytics
|
||||||
Type: Package
|
Type: Package
|
||||||
Title: Utilities Functions for Civilytics
|
Title: Utilities Functions for Civilytics
|
||||||
Version: 0.1.0
|
Version: 0.1.0
|
||||||
Author: Jared E. Knowles <jared@civilytics.com>
|
Author: Jared E. Knowles <jared@civilytics.com>
|
||||||
Maintainer: Jared E. Knowles <jared@civilytics.com>
|
Maintainer: Jared E. Knowles <jared@civilytics.com>
|
||||||
Description: House R functions for Civilytics Consulting LLC
|
Description: House R functions for Civilytics Consulting LLC
|
||||||
This package implements a variety of useful functions for creating and
|
This package implements a variety of useful functions for creating and
|
||||||
branding analyses produced by Civilytics Consulting LLC.
|
branding analyses produced by Civilytics Consulting LLC.
|
||||||
License: LICENSE
|
License: LICENSE
|
||||||
Depends:
|
Depends:
|
||||||
R (>= 2.15.1)
|
R (>= 2.15.1)
|
||||||
Imports:
|
Imports:
|
||||||
ggplot2,
|
ggplot2,
|
||||||
jpeg,
|
jpeg,
|
||||||
png,
|
png,
|
||||||
stringr,
|
stringr,
|
||||||
gridExtra,
|
gridExtra,
|
||||||
grid
|
grid
|
||||||
Encoding: UTF-8
|
Encoding: UTF-8
|
||||||
LazyData: true
|
LazyData: true
|
||||||
Suggests:
|
Suggests:
|
||||||
testthat
|
testthat
|
||||||
RoxygenNote: 7.1.1
|
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
|
||||||
@@ -37,8 +37,6 @@ countCleanr <- function(x){
|
|||||||
#'
|
#'
|
||||||
#' @return the names of columns in the dataframe with one or more entries equal to "."
|
#' @return the names of columns in the dataframe with one or more entries equal to "."
|
||||||
#' @export
|
#' @export
|
||||||
#'
|
|
||||||
#' @examples
|
|
||||||
findDots <- function(data){
|
findDots <- function(data){
|
||||||
return(names(data)[lapply(data, countDots) > 0])
|
return(names(data)[lapply(data, countDots) > 0])
|
||||||
|
|
||||||
@@ -49,9 +47,8 @@ findDots <- function(data){
|
|||||||
#' @param x a character vector
|
#' @param x a character vector
|
||||||
#'
|
#'
|
||||||
#' @return
|
#' @return
|
||||||
|
#' An integer counting the number of "." occurences in a vector
|
||||||
#' @export
|
#' @export
|
||||||
#'
|
|
||||||
#' @examples
|
|
||||||
countDots <- function(x){
|
countDots <- function(x){
|
||||||
len <- length(x[x == "." & !is.na(x)])
|
len <- length(x[x == "." & !is.na(x)])
|
||||||
totlen <- length(x)
|
totlen <- length(x)
|
||||||
@@ -65,8 +62,6 @@ countDots <- function(x){
|
|||||||
#'
|
#'
|
||||||
#' @return a vector the same length as the input vector with clean names
|
#' @return a vector the same length as the input vector with clean names
|
||||||
#' @export
|
#' @export
|
||||||
#'
|
|
||||||
#' @examples
|
|
||||||
dbSafeNames <- function(names) {
|
dbSafeNames <- function(names) {
|
||||||
names = gsub('[^a-z0-9]+','_',tolower(names))
|
names = gsub('[^a-z0-9]+','_',tolower(names))
|
||||||
names = make.names(names, unique = TRUE, allow_ = TRUE)
|
names = make.names(names, unique = TRUE, allow_ = TRUE)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#' @importFrom jpeg readJPEG
|
#' @importFrom jpeg readJPEG
|
||||||
#' @importFrom graphics rasterImage
|
#' @importFrom graphics rasterImage
|
||||||
#' @examples
|
#' @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(img)
|
||||||
plot_jpeg <- function(path, add=FALSE, upscale = TRUE)
|
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
|
#' @param filename a character with file path to a png file
|
||||||
#'
|
#'
|
||||||
#' @return
|
#' @return a plotted rasteGrob of a png image
|
||||||
#' @export
|
#' @export
|
||||||
#' @importFrom png readPNG
|
#' @importFrom png readPNG
|
||||||
#' @importFrom grid rasterGrob
|
#' @importFrom grid rasterGrob
|
||||||
#'
|
|
||||||
#' @examples
|
|
||||||
#'
|
|
||||||
get_png <- function(filename) {
|
get_png <- function(filename) {
|
||||||
grid::rasterGrob(png::readPNG(filename), interpolate = TRUE)
|
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 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
|
#' @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 ggplot2 theme
|
||||||
#' @importFrom gridExtra arrangeGrob
|
#' @importFrom gridExtra arrangeGrob
|
||||||
#' @export
|
#' @export
|
||||||
#'
|
|
||||||
#' @examples
|
|
||||||
add_logo <- function(plot, logo, margin_param = NULL) {
|
add_logo <- function(plot, logo, margin_param = NULL) {
|
||||||
if(has_caption(plot)) {
|
if(has_caption(plot)) {
|
||||||
# convert the caption size to a negative number and on the "pt" scale
|
# convert the caption size to a negative number and on the "pt" scale
|
||||||
@@ -84,7 +79,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)) {
|
||||||
@@ -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 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
|
#' @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()
|
#' @note The resulting object needs to be drawn to the screen using grid.draw()
|
||||||
#' @importFrom gridExtra arrangeGrob
|
#' @importFrom gridExtra arrangeGrob
|
||||||
#' @importFrom ggplot2 theme
|
#' @importFrom ggplot2 theme
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ pretty_count <- function(x) {
|
|||||||
|
|
||||||
#' Unsuppress data using sampling
|
#' Unsuppress data using sampling
|
||||||
#'
|
#'
|
||||||
#' @param x
|
#' @param x a vector
|
||||||
#' @param replace_char the character you want to replace in the 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 zeros the number of zeroes to oversample when replacing replace_char
|
||||||
#' @param max_value the numeric maximum value the replacement for the "*" can be
|
#' @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
|
#' @param x character description of grade levels from NCES style data
|
||||||
#'
|
#'
|
||||||
#' @return
|
#' @return a numeric vector
|
||||||
#' @export
|
#' @export
|
||||||
#'
|
#'
|
||||||
#' @examples
|
#' @examples
|
||||||
|
#' grade_level_to_num(c("KG", "Pre-K", "12", "10", "09"))
|
||||||
grade_level_to_num <- function(x) {
|
grade_level_to_num <- function(x) {
|
||||||
# Cannot generate new levels if it is a factor so we coerce to character first
|
# Cannot generate new levels if it is a factor so we coerce to character first
|
||||||
x <- as.character(x)
|
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
|
#' @param x a character vector with NCES race codes, often from Urban Institute
|
||||||
#'
|
#'
|
||||||
#' @return
|
#' @return recoded race categories following NCES race codes
|
||||||
#' @export
|
#' @export
|
||||||
#'
|
#'
|
||||||
#' @examples
|
#' @examples
|
||||||
|
#' race_short_names(c("Black", "Hispanic Or Latino", "Two Or More Races"))
|
||||||
race_short_names <- function(x) {
|
race_short_names <- function(x) {
|
||||||
x <- as.character(x)
|
x <- as.character(x)
|
||||||
x[x %in% c("Black", "Black Or African American", "Black or African American",
|
x[x %in% c("Black", "Black Or African American", "Black or African American",
|
||||||
|
|||||||
+1
-1
@@ -14,7 +14,7 @@ add_logo(plot, logo, margin_param = NULL)
|
|||||||
\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{
|
\value{
|
||||||
|
a grob with a logo attached to it ready to plot
|
||||||
}
|
}
|
||||||
\description{
|
\description{
|
||||||
Add a logo to a ggplot2 object
|
Add a logo to a ggplot2 object
|
||||||
|
|||||||
+1
-1
@@ -18,7 +18,7 @@ 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}
|
\item{margin_param}{a number giving the adjustment up or down to help manually align logo and captions}
|
||||||
}
|
}
|
||||||
\value{
|
\value{
|
||||||
|
a grid object
|
||||||
}
|
}
|
||||||
\description{
|
\description{
|
||||||
Add a logo to a ggplot2 object
|
Add a logo to a ggplot2 object
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ countDots(x)
|
|||||||
\item{x}{a character vector}
|
\item{x}{a character vector}
|
||||||
}
|
}
|
||||||
\value{
|
\value{
|
||||||
|
An integer counting the number of "." occurences in a vector
|
||||||
}
|
}
|
||||||
\description{
|
\description{
|
||||||
Count the number of single period entries in a vector
|
Count the number of single period entries in a vector
|
||||||
|
|||||||
+1
-4
@@ -10,11 +10,8 @@ get_png(filename)
|
|||||||
\item{filename}{a character with file path to a png file}
|
\item{filename}{a character with file path to a png file}
|
||||||
}
|
}
|
||||||
\value{
|
\value{
|
||||||
|
a plotted rasteGrob of a png image
|
||||||
}
|
}
|
||||||
\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{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -10,8 +10,11 @@ grade_level_to_num(x)
|
|||||||
\item{x}{character description of grade levels from NCES style data}
|
\item{x}{character description of grade levels from NCES style data}
|
||||||
}
|
}
|
||||||
\value{
|
\value{
|
||||||
|
a numeric vector
|
||||||
}
|
}
|
||||||
\description{
|
\description{
|
||||||
Recode grade level from character to numeric
|
Recode grade level from character to numeric
|
||||||
}
|
}
|
||||||
|
\examples{
|
||||||
|
grade_level_to_num(c("KG", "Pre-K", "12", "10", "09"))
|
||||||
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -21,6 +21,6 @@ a rasterImage
|
|||||||
Plot a jpeg image as a raster
|
Plot a jpeg image as a raster
|
||||||
}
|
}
|
||||||
\examples{
|
\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(img)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,11 @@ race_short_names(x)
|
|||||||
\item{x}{a character vector with NCES race codes, often from Urban Institute}
|
\item{x}{a character vector with NCES race codes, often from Urban Institute}
|
||||||
}
|
}
|
||||||
\value{
|
\value{
|
||||||
|
recoded race categories following NCES race codes
|
||||||
}
|
}
|
||||||
\description{
|
\description{
|
||||||
Recode NCES race categories to shorter names
|
Recode NCES race categories to shorter names
|
||||||
}
|
}
|
||||||
|
\examples{
|
||||||
|
race_short_names(c("Black", "Hispanic Or Latino", "Two Or More Races"))
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
star_subs(x, replace_char = "*", zeros = 15, max_value = 20)
|
star_subs(x, replace_char = "*", zeros = 15, max_value = 20)
|
||||||
}
|
}
|
||||||
\arguments{
|
\arguments{
|
||||||
|
\item{x}{a vector}
|
||||||
|
|
||||||
\item{replace_char}{the character you want to replace in the 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}
|
\item{zeros}{the number of zeroes to oversample when replacing replace_char}
|
||||||
|
|||||||
Reference in New Issue
Block a user