This commit is contained in:
+2
-1
@@ -17,7 +17,8 @@ Imports:
|
|||||||
stringr,
|
stringr,
|
||||||
gridExtra,
|
gridExtra,
|
||||||
tidycensus,
|
tidycensus,
|
||||||
grid
|
grid,
|
||||||
|
stringdist
|
||||||
Encoding: UTF-8
|
Encoding: UTF-8
|
||||||
LazyData: true
|
LazyData: true
|
||||||
Suggests:
|
Suggests:
|
||||||
|
|||||||
+1
-1
@@ -19,4 +19,4 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|||||||
&& rm -rf /var/lib/apt/lists/* \
|
&& rm -rf /var/lib/apt/lists/* \
|
||||||
&& mkdir -p /var/lib/shiny-server/bookmarks/shiny
|
&& mkdir -p /var/lib/shiny-server/bookmarks/shiny
|
||||||
|
|
||||||
RUN install2.r ggplot2 jpeg png stringr gridExtra grid testthat covr tidycensus
|
RUN install2.r ggplot2 jpeg png stringr gridExtra grid testthat covr tidycensus stringdist
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ export(nvals)
|
|||||||
export(outersect)
|
export(outersect)
|
||||||
export(perturb_count)
|
export(perturb_count)
|
||||||
export(plot_jpeg)
|
export(plot_jpeg)
|
||||||
|
export(postcode_lookup)
|
||||||
export(pretty_count)
|
export(pretty_count)
|
||||||
export(pretty_per)
|
export(pretty_per)
|
||||||
export(race_short_names)
|
export(race_short_names)
|
||||||
@@ -33,6 +34,7 @@ export(theme_civilytics)
|
|||||||
export(z_gap_test)
|
export(z_gap_test)
|
||||||
export(z_univariate)
|
export(z_univariate)
|
||||||
import(ggplot2)
|
import(ggplot2)
|
||||||
|
import(tidycensus)
|
||||||
importFrom(ggplot2,theme)
|
importFrom(ggplot2,theme)
|
||||||
importFrom(graphics,plot)
|
importFrom(graphics,plot)
|
||||||
importFrom(graphics,rasterImage)
|
importFrom(graphics,rasterImage)
|
||||||
@@ -41,5 +43,6 @@ importFrom(grid,rasterGrob)
|
|||||||
importFrom(gridExtra,arrangeGrob)
|
importFrom(gridExtra,arrangeGrob)
|
||||||
importFrom(jpeg,readJPEG)
|
importFrom(jpeg,readJPEG)
|
||||||
importFrom(png,readPNG)
|
importFrom(png,readPNG)
|
||||||
|
importFrom(stats,runif)
|
||||||
|
importFrom(stringdist,stringsim)
|
||||||
importFrom(stringr,str_count)
|
importFrom(stringr,str_count)
|
||||||
importFrom(tidycensus,fips_codes)
|
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
#' @param y a vector of identifiers to check against x
|
#' @param y a vector of identifiers to check against x
|
||||||
#' @param distinct logical, should duplicate values of x and y be removed before testing
|
#' @param distinct logical, should duplicate values of x and y be removed before testing
|
||||||
#'
|
#'
|
||||||
#' @return
|
#' @return nothing, print a summary of match statistics to the console
|
||||||
#' @export
|
#' @export
|
||||||
#'
|
#'
|
||||||
#' @examples
|
#' @examples
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ race_short_names <- function(x) {
|
|||||||
#' na_sum(x) # 15
|
#' na_sum(x) # 15
|
||||||
na_sum <- function(x) {
|
na_sum <- function(x) {
|
||||||
stopifnot(is.numeric(x))
|
stopifnot(is.numeric(x))
|
||||||
message("Taking a sum with missing values equal to 0, be careful 🐲")
|
message("Taking a sum with missing values equal to 0, be careful! \u1F601")
|
||||||
x <- na_zero(x)
|
x <- na_zero(x)
|
||||||
return(sum(x))
|
return(sum(x))
|
||||||
}
|
}
|
||||||
@@ -168,6 +168,15 @@ na_sum <- function(x) {
|
|||||||
# It also substitutes in PR and DC for Puerto Rico and District of Columbia
|
# It also substitutes in PR and DC for Puerto Rico and District of Columbia
|
||||||
# which are not included in the lookup table of states and state abbreviations
|
# which are not included in the lookup table of states and state abbreviations
|
||||||
# that comes with R.
|
# that comes with R.
|
||||||
|
#' Title
|
||||||
|
#'
|
||||||
|
#' @param x a vector of state names
|
||||||
|
## #' @importFrom datasets state.abb state.name
|
||||||
|
#' @return state abbreviations matching state naems provided in X
|
||||||
|
#' @export
|
||||||
|
#'
|
||||||
|
#' @examples
|
||||||
|
#' postcode_lookup("Montana")
|
||||||
postcode_lookup <- function(x) {
|
postcode_lookup <- function(x) {
|
||||||
modify_name <- c(state.name, "District of Columbia", "Puerto Rico")
|
modify_name <- c(state.name, "District of Columbia", "Puerto Rico")
|
||||||
modify_abb <- c(state.abb, "DC", "PR")
|
modify_abb <- c(state.abb, "DC", "PR")
|
||||||
@@ -181,6 +190,7 @@ postcode_lookup <- function(x) {
|
|||||||
#' @param x, the character value to match
|
#' @param x, the character value to match
|
||||||
#' @param y, a vector of multiple character values to look for a match in
|
#' @param y, a vector of multiple character values to look for a match in
|
||||||
#' @param n, an integer, how many matches to return
|
#' @param n, an integer, how many matches to return
|
||||||
|
#' @importFrom stringdist stringsim
|
||||||
#'
|
#'
|
||||||
#' @return an integer giving the position of the table with the most characters
|
#' @return an integer giving the position of the table with the most characters
|
||||||
trunc_match <- function(x, y, n) {
|
trunc_match <- function(x, y, n) {
|
||||||
@@ -224,8 +234,8 @@ outersect <- function(x, y, ...) {
|
|||||||
#' @param stabbr a two letter abbreviation for a US state
|
#' @param stabbr a two letter abbreviation for a US state
|
||||||
#'
|
#'
|
||||||
#' @return FIPS codes that match the abbreviation
|
#' @return FIPS codes that match the abbreviation
|
||||||
|
#' @import tidycensus
|
||||||
#' @export
|
#' @export
|
||||||
#' @importFrom tidycensus fips_codes
|
|
||||||
#'
|
#'
|
||||||
#' @examples
|
#' @examples
|
||||||
#' get_fips("MT")
|
#' get_fips("MT")
|
||||||
@@ -243,8 +253,8 @@ get_fips <- function(stabbr) {
|
|||||||
#' @param fips a character value that captures the FIPS code with leading 0
|
#' @param fips a character value that captures the FIPS code with leading 0
|
||||||
#'
|
#'
|
||||||
#' @return a character value, length 2, with the state abbreviation
|
#' @return a character value, length 2, with the state abbreviation
|
||||||
|
#' @import tidycensus
|
||||||
#' @export
|
#' @export
|
||||||
#' @importFrom tidycensus fips_codes
|
|
||||||
#'
|
#'
|
||||||
#' @examples
|
#' @examples
|
||||||
#' get_stabbr("06")
|
#' get_stabbr("06")
|
||||||
@@ -339,7 +349,7 @@ z_univariate <- function(unit_prop, global_prop, unit_denom) {
|
|||||||
#' @details The count in the name means that this function enforces a floor of
|
#' @details The count in the name means that this function enforces a floor of
|
||||||
#' 0 on values, so values perturbed to have less than 0 will be capped at 0.
|
#' 0 on values, so values perturbed to have less than 0 will be capped at 0.
|
||||||
#'
|
#'
|
||||||
#' @return
|
#' @return a numeric vector
|
||||||
#' @export
|
#' @export
|
||||||
#'
|
#'
|
||||||
#' @examples
|
#' @examples
|
||||||
@@ -361,6 +371,7 @@ perturb_count <- function(x, fac = 3) {
|
|||||||
#' @return rounded values
|
#' @return rounded values
|
||||||
#' @export
|
#' @export
|
||||||
#' @details Credit to Jens von Bergmann for this algo https://github.com/mountainMath/dotdensity/blob/master/R/dot-density.R
|
#' @details Credit to Jens von Bergmann for this algo https://github.com/mountainMath/dotdensity/blob/master/R/dot-density.R
|
||||||
|
#' @importFrom stats runif
|
||||||
#'
|
#'
|
||||||
#' @examples
|
#' @examples
|
||||||
#' random_round(1.93)
|
#' random_round(1.93)
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ match_test(x, y, distinct = TRUE)
|
|||||||
|
|
||||||
\item{distinct}{logical, should duplicate values of x and y be removed before testing}
|
\item{distinct}{logical, should duplicate values of x and y be removed before testing}
|
||||||
}
|
}
|
||||||
|
\value{
|
||||||
|
nothing, print a summary of match statistics to the console
|
||||||
|
}
|
||||||
\description{
|
\description{
|
||||||
Test the join between two sets of identifiers
|
Test the join between two sets of identifiers
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ perturb_count(x, fac = 3)
|
|||||||
|
|
||||||
\item{fac}{the range of values to add or subtract to perturb the count}
|
\item{fac}{the range of values to add or subtract to perturb the count}
|
||||||
}
|
}
|
||||||
|
\value{
|
||||||
|
a numeric vector
|
||||||
|
}
|
||||||
\description{
|
\description{
|
||||||
Add a random jitter to a count variable to mask its true value
|
Add a random jitter to a count variable to mask its true value
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
% Generated by roxygen2: do not edit by hand
|
||||||
|
% Please edit documentation in R/utils.R
|
||||||
|
\name{postcode_lookup}
|
||||||
|
\alias{postcode_lookup}
|
||||||
|
\title{Title}
|
||||||
|
\usage{
|
||||||
|
postcode_lookup(x)
|
||||||
|
}
|
||||||
|
\arguments{
|
||||||
|
\item{x}{a vector of state names}
|
||||||
|
}
|
||||||
|
\value{
|
||||||
|
state abbreviations matching state naems provided in X
|
||||||
|
}
|
||||||
|
\description{
|
||||||
|
Title
|
||||||
|
}
|
||||||
|
\examples{
|
||||||
|
postcode_lookup("Montana")
|
||||||
|
}
|
||||||
@@ -50,7 +50,7 @@ test_that("Function subs out NAs in numeric vectors with 0", {
|
|||||||
# Test that na_sum works
|
# Test that na_sum works
|
||||||
test_that("NA Sum takes sum setting NA values to 0", {
|
test_that("NA Sum takes sum setting NA values to 0", {
|
||||||
expect_equivalent(na_sum(c(1:10, NA)), sum(1:10, 0))
|
expect_equivalent(na_sum(c(1:10, NA)), sum(1:10, 0))
|
||||||
expect_message(na_sum(c(1:10, NA)), "Taking a sum with missing values equal to 0, be careful 🐲")
|
expect_message(na_sum(c(1:10, NA)), "Taking a sum with missing values equal to 0, be careful! \u1F601")
|
||||||
})
|
})
|
||||||
|
|
||||||
test_that("na_sum fails with non-numerics", {
|
test_that("na_sum fails with non-numerics", {
|
||||||
|
|||||||
Reference in New Issue
Block a user