Skip to content

Commit

Permalink
beyond frustrated ...
Browse files Browse the repository at this point in the history
  • Loading branch information
atyre2 committed Sep 16, 2020
1 parent 922d278 commit 5a441c1
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 5 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Generated by roxygen2: do not edit by hand

export(assemble_data)
export(fit_models)
11 changes: 8 additions & 3 deletions R/assemble_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,27 @@
#' @param path_2_case_data character file path to the case data
#' @param case_type character type of case data
#' @param case_variable character name of the case field in the case data
#' @param match_variable character name of the field to match data on
#'
#' @return a data.frame ready to estimate distributed lag models
#' @export
#'
assemble_data <- function(x, path_2_case_data = here::here("data-raw/wnv_by_county.csv"),
case_type = c("neuro", "all"),
case_variable = "cases"){
if(is.null(x) | !is.data.frame(x) | !tibble::is_tibble(x)){
match_variable = "fips",
case_variable = "cases"
){
if(is.null(x) | !(is.data.frame(x) | tibble::is_tibble(x))){
stop("x must be a data frame or tibble.")
}
if(!file.exists(path_2_case_data)){
stop("Please provide a valid path to the WNV case data.")
} else {
wnvcases <- readr::read_csv(path_2_case_data)
mv1 <- eval(quote(match_variable), wnvcases)
mv2 <- eval(quote(match_variable), x)
# check that all targets exist in case data
missing_targets <- dplyr::anti_join(x, wnvcases, by = "fips")
missing_targets <- dplyr::anti_join(x, wnvcases, by = match_variable)
if (nrow(missing_targets) > 0){
stop("Some prediction targets have no matches in case data.")
}
Expand Down
33 changes: 33 additions & 0 deletions man/assemble_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/fit_models.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/sampledat.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/testthat/test-fit_models.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
data(sampledat)
test_that("data checks work", {
expect_error(fit_models(x = NULL), "x must be a data frame or tibble.")
expect_error(fit_models(x = sampledat, path_2_case_data = "almostcertainlynotavalidfile"),
Expand Down

0 comments on commit 5a441c1

Please sign in to comment.