Skip to content

Commit

Permalink
REL: v0.1.1 and prev output bug fix
Browse files Browse the repository at this point in the history
Fix
#34 (comment)
and roxygen comments.
  • Loading branch information
fredjaya committed Apr 16, 2024
1 parent 4868e50 commit 21f994e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 24 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased (To be deployed)
## [0.1.1] - 2024-04-16

### Added
- Roxygen comments to R util files.
- `utils_dt_display.R` to handle post-pooltestr processing.
- Prevalence division option (default 1/2000).
- Prevalence multiply option (default 1*2000).
- CITATION file.

### Changed
Expand Down
31 changes: 17 additions & 14 deletions R/utils_dt_display.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,41 +77,44 @@ bayes_cols <- c(
#' Display Prevalence and CI/CrI Per Value
#'
#' The development of intervention plans are often determined based on the
#' prevalence per a given value (e.g. 1/1000). This function applies this
#' transformation.
#' prevalence per a given value (e.g. multiplying by 2000 gives you the
#' prevalence per 2000 units). This function applies this transformation across
#' columns, as well as rounding (see note on rounding above).
#'
#' @param df dataframe PoolTestR output
#' @param ptr_mode character String indicating PoolTestR mode used. Get from
#' `which_pooltestr`.
#' @param val integer Value to divide prevalence and intervals by.
#'
#' @param per_prev boolean Should values be displayed `per_val`?
#' @param per_val integer Value to multiply prevalence and intervals by.
#' @param digits integer Number of digits to round by.

#' @return dataframe
#' @name prev_per_val
dt_display <- function(df, ptr_mode, divide_prev, divide_val, digits) {
#' @name dt_display
dt_display <- function(df, ptr_mode, per_prev, per_val, digits) {
# poolprev_bayes requires both transformations
if (!divide_prev) {
# Don't divide
if (!per_prev) {
# Don't multiply
val <- 1
} else {
val <- divide_val
val <- per_val
}
if (ptr_mode %in% c("poolprev", "poolprev_strat", "poolprev_bayes")) {
df <- df %>%
divide_cols(mle_cols, val) %>%
multiply_cols(mle_cols, val) %>%
round_pool_cols(digits = digits, cols = mle_cols)
}
if (ptr_mode %in% c("poolprev_bayes", "hierpoolprev", "hierpoolprev_strat")) {
df <- df %>%
divide_cols(bayes_cols, val) %>%
multiply_cols(bayes_cols, val) %>%
round_pool_cols(digits = digits, cols = bayes_cols)
}
return(df)
}

#' @rdname divide_cols
divide_cols <- function(df, cols, val) {
#' @rdname dt_display
multiply_cols <- function(df, cols, val) {
dplyr::mutate(
df,
dplyr::across(cols, ~ as.numeric(.) / val)
dplyr::across(cols, ~ as.numeric(.) * val)
)
}
2 changes: 1 addition & 1 deletion rsconnect/shinyapps.io/fredjaya/pooltools.dcf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ account: fredjaya
server: shinyapps.io
hostUrl: https://api.shinyapps.io/v1
appId: 10880234
bundleId: 8466707
bundleId: 8499472
url: https://fredjaya.shinyapps.io/pooltools/
version: 1
14 changes: 7 additions & 7 deletions server.R
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,16 @@ server <- function(input, output, session) {
# Prevalence and CI/CrI rounding
numericInput("optsRoundAnalyse", "Number of decimal places to display", value = 4),

# Should prevalence and CI/CrI be divided by a value?
# Should prevalence and CI/CrI be multiplied by a value?
checkboxInputTT(
"optsDividePrev",
"optsPerPrev",
"Display prevalence per value",
tooltip = "Selecting this option will divide prevalence and interval estimates by a given value",
tooltip = "Selecting this option will multiply prevalence and interval estimates by a given value",
value = F
),
conditionalPanel(
condition = "input.optsDividePrev == true",
numericInput("optsDividePrevVal", label = "Value", value = 2000, min = 1, step = 1)
condition = "input.optsPerPrev == true",
numericInput("optsPerPrevVal", label = "Value", value = 2000, min = 1, step = 1)
)
),
tags$br()
Expand Down Expand Up @@ -223,8 +223,8 @@ server <- function(input, output, session) {
data <- dt_display(
df = data,
ptr_mode = ptr_mode,
divide_prev = input$optsDividePrev,
divide_val = as.integer(input$optsDividePrevVal),
per_prev = input$optsPerPrev,
per_val = as.integer(input$optsPerPrevVal),
digits = as.integer(input$optsRoundAnalyse)
)

Expand Down

0 comments on commit 21f994e

Please sign in to comment.