This repository has been archived by the owner on Dec 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from slu-openGIS/cran-release
Cran release
- Loading branch information
Showing
66 changed files
with
1,807 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
This package was submitted to CRAN on 2019-03-22. | ||
Once it is accepted, delete this file and tag the release (commit e1edbe830f). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#' Create a Single Address Field | ||
#' | ||
#' @description The street address data in SLMPD releases (either \code{ILEADSAddress} and | ||
#' \code{ILEADSStreet} or \code{CADAddress} and \code{CADStreet}) are stored in separate | ||
#' columns. In order to faciliate geocoding, this function combines the fields and | ||
#' removes inappropriate characters in the address fields. | ||
#' | ||
#' @usage cs_address(.data, address, street, newVar) | ||
#' | ||
#' @param .data A tibble or data frame | ||
#' @param address Name of address number variable (typically either \code{ILEADSAddress} | ||
#' or \code{CADAddress}) | ||
#' @param street Name of street name variable (typically either \code{ILEADSStreet} | ||
#' or \code{CADStreet}) | ||
#' @param newVar Name of new variable to store concatenated address | ||
#' | ||
#' @return A copy of the object with a character vector that contains the concatenated | ||
#' street address data. | ||
#' | ||
#' @examples | ||
#' # load example data | ||
#' testData <- january2018 | ||
#' | ||
#' # add concatenated address variable | ||
#' testData <- cs_address(testData, address = ILEADSAddress, street = ILEADSStreet, newVar = address) | ||
#' | ||
#' @importFrom dplyr mutate | ||
#' @importFrom rlang := | ||
#' @importFrom rlang quo | ||
#' @importFrom rlang enquo | ||
#' @importFrom rlang sym | ||
#' @importFrom stringr str_c | ||
#' @importFrom stringr str_detect | ||
#' @importFrom stringr str_replace | ||
#' @importFrom stringr str_trim | ||
#' | ||
#' @export | ||
cs_address <- function(.data, address, street, newVar){ | ||
|
||
# check for missing parameters | ||
if (missing(.data)) { | ||
stop("An existing data frame with crime data must be specified for '.data'.") | ||
} | ||
|
||
if (missing(address)) { | ||
stop("The column containing address numbers must be specified for 'address'.") | ||
} | ||
|
||
if (missing(street)) { | ||
stop("The column containing street names must be specified for 'street'.") | ||
} | ||
|
||
if (missing(newVar)) { | ||
stop("A new variable name must be specified for 'newVar'.") | ||
} | ||
|
||
#save parameters to list | ||
paramList <- as.list(match.call()) | ||
|
||
#quote input variables | ||
if (!is.character(paramList$address)) { | ||
addressQ <- rlang::enquo(address) | ||
} else if (is.character(paramList$address)) { | ||
addressQ <- rlang::quo(!! rlang::sym(address)) | ||
} | ||
|
||
if (!is.character(paramList$street)) { | ||
streetQ <- rlang::enquo(street) | ||
} else if (is.character(paramList$street)) { | ||
streetQ <- rlang::quo(!! rlang::sym(street)) | ||
} | ||
|
||
if (!is.character(paramList$newVar)) { | ||
newVarQ <- rlang::enquo(newVar) | ||
} else if (is.character(paramList$newVar)) { | ||
newVarQ <- rlang::quo(!! rlang::sym(newVar)) | ||
} | ||
|
||
newVarQN <- rlang::quo_name(rlang::enquo(newVar)) | ||
|
||
# concatenate address | ||
.data <- dplyr::mutate(.data, !!newVarQN := stringr::str_c(!!addressQ, !!streetQ, sep = " ")) | ||
|
||
# clean address | ||
.data <- dplyr::mutate(.data, !!newVarQN := ifelse(stringr::str_detect(string = !!newVarQ, pattern = "^[0\\b]") == TRUE, | ||
stringr::str_replace(string = !!newVarQ, pattern = "^[0\\b]", replacement = ""), | ||
address)) | ||
.data <- dplyr::mutate(.data, !!newVarQN := stringr::str_trim(!!newVarQ)) | ||
|
||
# return output | ||
return(.data) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#' Load Example Files | ||
#' | ||
#' @description Adds a sample set of twelve files, one for each month of 2017, | ||
#' to the specified path. These are not full data files; each file has twenty | ||
#' observations. They can be used to practice preparing, loading, standardizing, | ||
#' and collapsing data. | ||
#' | ||
#' @param path File path where example data should be placed | ||
#' @param overwrite Overwrite files if they exist. If this is FALSE and the file exists | ||
#' an error will be thrown. | ||
#' | ||
#' @examples | ||
#' # create temporary directory | ||
#' tmpdir <- tempdir() | ||
#' fs::dir_create(paste0(tmpdir,"/data/")) | ||
#' | ||
#' # load sample files into temporary directory | ||
#' cs_example(path = paste0(tmpdir,"/data/")) | ||
#' | ||
#' # list files | ||
#' list.files(paste0(tmpdir,"/data/")) | ||
#' | ||
#' # delete data | ||
#' fs::dir_delete(paste0(tmpdir,"/data/")) | ||
#' | ||
#' @importFrom fs file_copy | ||
#' | ||
#' @export | ||
cs_example <- function(path, overwrite = FALSE){ | ||
|
||
# copy file, january | ||
fs::file_copy(system.file("extdata", "January2017.csv.html", package = "compstatr", mustWork = TRUE), | ||
paste0(path,"/January2017.CSV.html"), overwrite = overwrite) | ||
|
||
# copy file, february | ||
fs::file_copy(system.file("extdata", "February2017.csv.html", package = "compstatr", mustWork = TRUE), | ||
paste0(path,"/February2017.CSV.html"), overwrite = overwrite) | ||
|
||
# copy file, march | ||
fs::file_copy(system.file("extdata", "March2017.csv.html", package = "compstatr", mustWork = TRUE), | ||
paste0(path,"/March2017.CSV.html"), overwrite = overwrite) | ||
|
||
# copy file, april | ||
fs::file_copy(system.file("extdata", "April2017.csv.html", package = "compstatr", mustWork = TRUE), | ||
paste0(path,"/April2017.CSV.html"), overwrite = overwrite) | ||
|
||
# copy file, may | ||
fs::file_copy(system.file("extdata", "May2017.csv.html", package = "compstatr", mustWork = TRUE), | ||
paste0(path,"/May2017.CSV.html"), overwrite = overwrite) | ||
|
||
# copy file, june | ||
fs::file_copy(system.file("extdata", "June2017.csv.html", package = "compstatr", mustWork = TRUE), | ||
paste0(path,"/June2017.CSV.html"), overwrite = overwrite) | ||
|
||
# copy file, july | ||
fs::file_copy(system.file("extdata", "July2017.csv.html", package = "compstatr", mustWork = TRUE), | ||
paste0(path,"/July2017.CSV.html"), overwrite = overwrite) | ||
|
||
# copy file, august | ||
fs::file_copy(system.file("extdata", "August2017.csv.html", package = "compstatr", mustWork = TRUE), | ||
paste0(path,"/August2017.CSV.html"), overwrite = overwrite) | ||
|
||
# copy file, september | ||
fs::file_copy(system.file("extdata", "September2017.csv.html", package = "compstatr", mustWork = TRUE), | ||
paste0(path,"/September2017.CSV.html"), overwrite = overwrite) | ||
|
||
# copy file, october | ||
fs::file_copy(system.file("extdata", "October2017.csv.html", package = "compstatr", mustWork = TRUE), | ||
paste0(path,"/October2017.CSV.html"), overwrite = overwrite) | ||
|
||
# copy file, november | ||
fs::file_copy(system.file("extdata", "November2017.csv.html", package = "compstatr", mustWork = TRUE), | ||
paste0(path,"/November2017.CSV.html"), overwrite = overwrite) | ||
|
||
# copy file, december | ||
fs::file_copy(system.file("extdata", "December2017.csv.html", package = "compstatr", mustWork = TRUE), | ||
paste0(path,"/December2017.CSV.html"), overwrite = overwrite) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.