From e75a336e0248298958c76a4faff618b0c46ae75a Mon Sep 17 00:00:00 2001 From: Jean Cochrane Date: Tue, 3 Dec 2024 11:26:59 -0600 Subject: [PATCH] Remove deprecated `vars_check_class` function from R package --- NAMESPACE | 1 - R/vars_funs.R | 64 --------------------------------- _pkgdown.yml | 1 - tests/testthat/test-vars_funs.R | 35 ------------------ 4 files changed, 101 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 5aedc00..a9206df 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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,"%>%") diff --git a/R/vars_funs.R b/R/vars_funs.R index 62506a0..76103fa 100644 --- a/R/vars_funs.R +++ b/R/vars_funs.R @@ -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 #' diff --git a/_pkgdown.yml b/_pkgdown.yml index 70baf43..801a9c0 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -43,7 +43,6 @@ reference: - chars_fix_age - chars_sparsify - chars_update - - vars_check_class - vars_recode - vars_rename - subtitle: Adjust estimated values diff --git a/tests/testthat/test-vars_funs.R b/tests/testthat/test-vars_funs.R index 3184f60..1a29513 100644 --- a/tests/testthat/test-vars_funs.R +++ b/tests/testthat/test-vars_funs.R @@ -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() #####