Skip to content

Commit

Permalink
new check inherits function and rebuilt readme
Browse files Browse the repository at this point in the history
  • Loading branch information
joshyam-k committed Jun 3, 2024
1 parent 07c33eb commit 6837eda
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
12 changes: 6 additions & 6 deletions R/saeczi.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ saeczi <- function(samp_dat,

funcCall <- match.call()

check_inherits(list(samp_dat, pop_dat), "data.frame")
check_inherits(list(lin_formula, log_formula), "formula")
check_inherits(list(domain_level, estimand), "character")
check_inherits(B, "integer")
check_inherits(list(mse_est, parallel), "logical")

check_inherits("data.frame", samp_dat, pop_dat)
check_inherits("formula", lin_formula, log_formula)
check_inherits("character", domain_level, estimand)
check_inherits("integer", B)
check_inherits("logical", mse_est, parallel)
check_parallel(parallel)
check_re(pop_dat, samp_dat, domain_level)

Expand Down
17 changes: 10 additions & 7 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -516,18 +516,21 @@ capture_all <- function(.f){

#' Checking if a param inherits a class
#'
#' @param x The parameter input(s) to check
#' @param what What class to check if the parameter input inherits
#' @param ... The parameter input(s) to check
#'
#' @return Nothing if the check is passed, but an error if the check fails
#' @noRd
check_inherits <- function(x, what) {
for (i in seq_along(x)) {
if (!inherits(x[[i]], what)) {
stop(paste0(x[[i]], " needs to be of class ", what))
check_inherits <- function(what, ...) {
opts <- list(...)
for (i in seq_along(opts)) {
if (!is.null(opts[[i]])) {
if (!inherits(opts[[i]], what)) {
stop(paste0(opts[[i]], " needs to be of class ", what))
}
}
}
invisible(x)
} # i
invisible(opts)
}

#' Checking if parallel functionality is properly set up
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ few rows of the results:

``` r
result$res |> head()
#> COUNTYFIPS mse est
#> 1 41001 191.5390 14.57288
#> 2 41003 94.7348 103.33016
#> 3 41005 173.1457 86.08616
#> 4 41007 383.6601 78.79615
#> 5 41009 830.4163 73.98920
#> 6 41011 113.1575 90.44174
#> COUNTYFIPS mse est
#> 1 41001 38.30647 14.57288
#> 2 41003 122.90662 103.33016
#> 3 41005 1069.30963 86.08616
#> 4 41007 4691.01214 78.79615
#> 5 41009 356.53805 73.98920
#> 6 41011 273.34697 90.44174
```

### Parallelization
Expand Down

0 comments on commit 6837eda

Please sign in to comment.