-
Notifications
You must be signed in to change notification settings - Fork 0
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 #12 from PIP-Technical-Team/pipster_functions
Pipster functions (md_functions and gd_functions)
- Loading branch information
Showing
91 changed files
with
8,424 additions
and
553 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 |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
^docs$ | ||
^pkgdown$ | ||
^\.github$ | ||
^codecov\.yml$ |
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,50 @@ | ||
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples | ||
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help | ||
on: | ||
push: | ||
branches: [main, master] | ||
pull_request: | ||
branches: [main, master] | ||
|
||
name: test-coverage | ||
|
||
jobs: | ||
test-coverage: | ||
runs-on: ubuntu-latest | ||
env: | ||
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: r-lib/actions/setup-r@v2 | ||
with: | ||
use-public-rspm: true | ||
|
||
- uses: r-lib/actions/setup-r-dependencies@v2 | ||
with: | ||
extra-packages: any::covr | ||
needs: coverage | ||
|
||
- name: Test coverage | ||
run: | | ||
covr::codecov( | ||
quiet = FALSE, | ||
clean = FALSE, | ||
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package") | ||
) | ||
shell: Rscript {0} | ||
|
||
- name: Show testthat output | ||
if: always() | ||
run: | | ||
## -------------------------------------------------------------------- | ||
find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true | ||
shell: bash | ||
|
||
- name: Upload test results | ||
if: failure() | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: coverage-test-failures | ||
path: ${{ runner.temp }}/package |
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 |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
.RData | ||
.Ruserdata | ||
docs | ||
inst/doc |
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 |
---|---|---|
@@ -1,28 +1,38 @@ | ||
Package: pipster | ||
Title: What the Package Does (One Line, Title Case) | ||
Version: 0.0.0.9002 | ||
Version: 0.0.1 | ||
Authors@R: c( | ||
person( | ||
"R.Andres", "Castaneda", | ||
email = "[email protected]", | ||
role = c("aut", "cre") | ||
)) | ||
), | ||
person(given = "Zander", | ||
family = "Prinsloo", | ||
role = "aut", | ||
email = "[email protected]") | ||
) | ||
Description: What the package does (one paragraph). | ||
License: MIT + file LICENSE | ||
Encoding: UTF-8 | ||
Roxygen: list(markdown = TRUE) | ||
RoxygenNote: 7.2.3 | ||
RoxygenNote: 7.3.1 | ||
Suggests: | ||
knitr, | ||
rmarkdown, | ||
testthat (>= 3.0.0), | ||
tibble, | ||
withr | ||
Config/testthat/edition: 3 | ||
Imports: | ||
cli, | ||
collapse, | ||
collapse (>= 2.0.9), | ||
data.table, | ||
wbpip (>= 0.1.0.9002) | ||
wbpip (>= 0.1.0.9012) | ||
Depends: | ||
R (>= 2.10) | ||
LazyData: true | ||
URL: https://pip-technical-team.github.io/pipster/ | ||
Remotes: | ||
github::PIP-Technical-Team/wbpip@dev_stage2 | ||
VignetteBuilder: knitr |
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,159 @@ | ||
#' Check parameters of pipgd functions | ||
#' | ||
#' @param lp list of parameters | ||
#' | ||
#' @return invisible TRUE | ||
#' @keywords internal | ||
check_pipgd_params <- function(lp) { | ||
|
||
# ____________________________________________________________________________ | ||
# Computations #### | ||
|
||
nlp <- names(lp) | ||
|
||
## params -------------------- | ||
if ("params" %in% nlp) { | ||
if (!is.null(lp$params) && !inherits(lp$params, "pipgd_params")) { | ||
cli::cli_abort(c("argument {.field params} must be of | ||
class {.code pipgd_params}.", | ||
"It should be created using {.fun pipgd_params}")) | ||
} | ||
} | ||
|
||
## welfare ----------- | ||
|
||
|
||
## welfare and params ----------- | ||
if ( all(c("params", "welfare") %in% nlp)) { | ||
if (!is.null(lp$params) && | ||
(!is.null(lp$welfare) || !is.null(lp$population))) { | ||
cli::cli_abort("You must specify either {.field params} or | ||
{.field welfare} and {.field population}") | ||
} | ||
} | ||
|
||
|
||
## povline and popshare ---------- | ||
if ( all(c("povline", "popshare") %in% nlp)) { | ||
if (!is.na(lp$povline) && !is.null(lp$popshare)) { | ||
cli::cli_abort("You must specify either {.field povline} or | ||
{.field popshare}") | ||
} | ||
} | ||
|
||
if ("popshare" %in% nlp) { | ||
if (any(lp$popshare <= 0)) { | ||
cli::cli_abort("All values in {.arg popshare} must be positve") | ||
} | ||
} | ||
|
||
if ("popshare" %in% nlp) { | ||
if (any(lp$popshare > 1)) { | ||
cli::cli_abort("No values in {.arg popshare} can be >1") | ||
} | ||
} | ||
|
||
|
||
# "Either `params` or `welfare` and `population` should be spefied" = | ||
# (is.null(params) && !is.null(welfare) && !is.null(population)) || | ||
# (!is.null(params) && is.null(welfare) && is.null(population)) | ||
# | ||
# "`params` should be a list from `pipgd_validate_lorenz()`" = | ||
# is.list(params) || is.null(params) | ||
# | ||
# "`complete` must be logical" = | ||
# is.logical(complete) | ||
|
||
## lorenz ----------- | ||
if ( all(c("lorenz") %in% nlp)) { | ||
|
||
if (!is.null(lp$lorenz) && !lp$lorenz %in% c("lq", "lb")) { | ||
|
||
cli::cli_abort("{.field lorenz} must be either 'lq' or 'lb', or | ||
{.code NULL} to let the algorithm select") | ||
} | ||
} | ||
|
||
|
||
# ____________________________________________________________________________ | ||
# Return #### | ||
return(invisible(TRUE)) | ||
|
||
} | ||
|
||
|
||
#' Check parameters of pipmd functions | ||
#' | ||
#' | ||
#' @return invisible TRUE | ||
#' @keywords internal | ||
check_pipmd_pov <- function() { | ||
lp <- parent.frame() |> | ||
as.list() | ||
|
||
with(lp, { | ||
if (is.na(welfare) |> any()) { | ||
cli::cli_abort("No elements in welfare vector can be NA") | ||
} | ||
if (!is.numeric(welfare)) { | ||
cli::cli_abort("welfare must be numeric") | ||
} | ||
|
||
if (length(weight) > 1 & any(is.na(weight))) { | ||
cli::cli_abort("No elements in weight vector can be NA - make NULL to use equal weighting") | ||
} | ||
|
||
if (is.null(povline) || !is.numeric(povline)) { | ||
cli::cli_abort( | ||
text = "A numeric poverty line must be specified" | ||
) | ||
} | ||
|
||
if (povline < min(welfare) || povline > max(welfare)) { | ||
cli::cli_alert_info( | ||
text = "Note: specified poverty line is not within the welfare range" | ||
) | ||
} | ||
}) | ||
|
||
# ____________________________________________________________________________ | ||
# Return #### | ||
return(invisible(TRUE)) | ||
|
||
} | ||
|
||
|
||
|
||
check_pipmd_dist <- function() { | ||
lp <- parent.frame() |> | ||
as.list() | ||
|
||
with(lp, { | ||
|
||
if (is.na(welfare) |> any()) { | ||
cli::cli_abort("No elements in welfare vector can be NA") | ||
} | ||
if (!is.numeric(welfare)) { | ||
cli::cli_abort("welfare must be numeric") | ||
} | ||
if (length(weight) > 1 & any(is.na(weight))) { | ||
cli::cli_abort("No elements in weight vector can be NA - make NULL to use equal weighting") | ||
} | ||
if (is.null(weight)) { | ||
weight <- rep(1, length = length(welfare)) | ||
cli::cli_alert_warning( | ||
text = "No weight vector specified, each observation assigned equal weight" | ||
) | ||
} | ||
|
||
if (exists("n", inherits = FALSE) & | ||
exists("popshare", inherits = FALSE)) { | ||
if (is.null(n) & is.null(popshare)) { | ||
cli::cli_abort("Either {.arg n} or {.arg popshare} must be defined") | ||
} | ||
} | ||
}) | ||
# ____________________________________________________________________________ | ||
# Return #### | ||
return(invisible(TRUE)) | ||
} |
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.