Skip to content

Commit

Permalink
Remove deprecated vars_check_class function from R package
Browse files Browse the repository at this point in the history
  • Loading branch information
jeancochrane committed Dec 3, 2024
1 parent 67ea0bb commit e75a336
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 101 deletions.
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export(town_get_assmnt_year)
export(town_get_triad)
export(val_limit_ratios)
export(val_round_fmv)
export(vars_check_class)
export(vars_recode)
export(vars_rename)
importFrom(magrittr,"%>%")
Expand Down
64 changes: 0 additions & 64 deletions R/vars_funs.R
Original file line number Diff line number Diff line change
@@ -1,67 +1,3 @@
#' Check if a property class falls within its expected square footage and age
#' boundaries
#'
#' @description Check property characteristics against class definitions as defined # nolint
#' \href{https://datascience.cookcountyassessor.com/wiki/data/class-definitions.pdf}{here}. # nolint
#'
#' @param age Integer or numeric vector of ages of properties. Either 1 long
#' or the same length as \code{sqft} and \code{class}.
#' @param sqft Integer or numeric vector of the square footage of properties.
#' Either 1 long or the same length as \code{age} and \code{class}.
#' @param class String or character vector of class codes. Either 1 long or
#' the same length as \code{sqft} and \code{age}.
#'
#' @return A logical vector indicating that the specified class falls within
#' the parameters specified by \code{\link{class_dict}}. Throws error if input
#' data types are incorrect or if length conditions of input vectors
#' are not met.
#'
#' @examples
#' vars_check_class(50, 800, "202")
#' vars_check_class(c(50, 80), c(800, 1000), c("202", "203"))
#' vars_check_class(c(50, 80), 1000, "210")
#' vars_check_class(50, c(800, 2000), "202")
#' vars_check_class(50, 1000, c("202", "203"))
#' @importFrom magrittr %>%
#' @importFrom rlang .data
#' @family vars_funs
#' @export
vars_check_class <- function(age, sqft, class) {
# Simple error checking
stopifnot(
is.numeric(age),
is.numeric(sqft),
is.character(class)
)

# Take only the classes from the dictionary which are residential (200)
res_classes <- dplyr::filter(
ccao::class_dict, substr(.data$class_code, 1, 1) == "2"
)

# Element-wise comparison to test that age & sqft return the expected class
mapply(
function(x, y, z) {
idx <- res_classes$min_age <= x &
res_classes$max_age >= x &
res_classes$min_size <= y &
res_classes$max_size >= y

possible_classes <- res_classes$class_code[idx]

if (length(possible_classes) == 0) {
return(NA)
} else {
return(z %in% possible_classes)
}
},
x = age, y = sqft, z = class,
USE.NAMES = FALSE,
SIMPLIFY = TRUE
)
}


#' Bulk rename variables from CCAO SQL to standardized or pretty names
#' and visa versa
#'
Expand Down
1 change: 0 additions & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ reference:
- chars_fix_age
- chars_sparsify
- chars_update
- vars_check_class
- vars_recode
- vars_rename
- subtitle: Adjust estimated values
Expand Down
35 changes: 0 additions & 35 deletions tests/testthat/test-vars_funs.R
Original file line number Diff line number Diff line change
@@ -1,38 +1,3 @@
context("test vars_check_class()")

##### TEST vars_check_class() #####

# Test for expected outputs
test_that("output is as expected", {
expect_equal(vars_check_class(50, 800, "202"), TRUE)
expect_equal(vars_check_class(50, 800, c("202", "299")), c(TRUE, TRUE))
expect_equal(vars_check_class(50, 800, c("202", "203")), c(TRUE, FALSE))
expect_equal(vars_check_class(62, 3000, c("206", "210")), c(FALSE, FALSE))
expect_equal(vars_check_class(c(62, 63), 800, "210"), c(FALSE, TRUE))
expect_equal(vars_check_class(-10, 200, "206"), NA)
})

test_that("invalid matches return false", {
expect_false(vars_check_class(50, 800, "190"), FALSE)
expect_false(vars_check_class(60, 1000, "202"))
expect_false(vars_check_class(62, 1500, "205"))
})


# Test that invalid inputs throw errors
test_that("invalid data types stop process", {
expect_condition(vars_check_class("50", 800, 202))
expect_condition(vars_check_class(50, "800", "202"))
expect_condition(vars_check_class(50, 800, 202))
})

test_that("invalid vector lengths stop process", {
expect_condition(vars_check_class(50, c(800, 1000, 2000), c("203", "204")))
expect_condition(vars_check_class(c(50, 80), c(800, 1000, 2000), "204"))
expect_condition(vars_check_class(5, c(800, 1000), c("203", "204", "297")))
})


context("test vars_rename()")

##### TEST vars_rename() #####
Expand Down

0 comments on commit e75a336

Please sign in to comment.