diff --git a/.gitignore b/.gitignore index 5799f8d..ca432fe 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .RData .Rproj.user /ignored +.DS_Store diff --git a/DESCRIPTION b/DESCRIPTION index a8d313b..6ffb718 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -13,7 +13,7 @@ Description: License: GPL-3 Encoding: UTF-8 LazyData: true -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 Imports: dplyr, readr, diff --git a/NAMESPACE b/NAMESPACE index 3c9a120..b7eb52c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -9,6 +9,7 @@ export(build_chairs) export(build_horse) export(build_table) export(check_grain) +export(create_status_cols) export(debark) export(dedupe_MA) export(do_MA) diff --git a/R/build_chairs.R b/R/build_chairs.R index 08a31d6..d7a40a8 100644 --- a/R/build_chairs.R +++ b/R/build_chairs.R @@ -47,12 +47,20 @@ #' #' @export +# Encapsulating odds_ratio and se_log_or separately +# When the grain is the odds_ratio, the function would just return the odds ratio passed (when flag is OR) +# If parameter se = TRUE, then pass se as well +# +# Support different log_base, default to exp(1) -- natural log base +# +# +# Next step: Create a function that works on tables, based on passed odds ratios/se build_chairs <- function(timber, log_base = exp(1)) { dplyr::mutate(timber, odds_ratio = dplyr::case_when( - grain == "odds_ratio" ~ odds, + grain == "odds_ratio" ~ odds, # Call this function, pass it with the odds ratio grain == "con_table_pos_neg" | grain == "con_table_pos_tot" | grain == "prev_table_pos_tot" ~ (A/B) / (C/D), TRUE ~ NA_real_), se_log_or = dplyr::case_when( diff --git a/R/check_grain.R b/R/check_grain.R index 648c47e..17b5ce8 100644 --- a/R/check_grain.R +++ b/R/check_grain.R @@ -133,20 +133,24 @@ check_grain <- function(timber) { timber[ , 'grain'] <- NA_character_ } - # Column `sawmill_pass` indicates whether sawmill should operate on the - # resistance outcome. Set `sawmill_pass = FALSE` after other co-occurring - # events during check failure. - if (!('sawmill_pass' %in% names(timber))) { - timber[ , 'sawmill_pass'] <- TRUE - message("Column 'sawmill_pass' did not exist and was created.") - } - - # Column `sawmill_status` indicates the current sawmill status. - # Set `sawmill_status` after every sawmill operation. - if (!('sawmill_status' %in% names(timber))) { - timber[ , 'sawmill_status'] <- 'Initialized.' - message("Column 'sawmill_status' did not exist and was created.") - } + # Initialize 'sawmill_pass' and 'sawmill_status' if they do not exist + create_status_cols(timber) + + + # # Column `sawmill_pass` indicates whether sawmill should operate on the + # # resistance outcome. Set `sawmill_pass = FALSE` after other co-occurring + # # events during check failure. + # if (!('sawmill_pass' %in% names(timber))) { + # timber[ , 'sawmill_pass'] <- TRUE + # message("Column 'sawmill_pass' did not exist and was created.") + # } + # + # # Column `sawmill_status` indicates the current sawmill status. + # # Set `sawmill_status` after every sawmill operation. + # if (!('sawmill_status' %in% names(timber))) { + # timber[ , 'sawmill_status'] <- 'Initialized.' + # message("Column 'sawmill_status' did not exist and was created.") + # } # Check if `res_format` is a supported grain -------------------------------- diff --git a/R/create_status_cols.R b/R/create_status_cols.R new file mode 100644 index 0000000..7df34db --- /dev/null +++ b/R/create_status_cols.R @@ -0,0 +1,50 @@ + + +#' @title +#' Initializes the `sawmill_status` and `sawmill_pass` columns at the start +#' of the \code{check_grain()} function +#' +#' @description +#' \code{create_status_cols()} adds columns to the passed tibble, containing +#' the sawmill status provided. +#' +#' @param timber +#' A tibble of timber, with a table built by \code{\link{build_table}}. +#' +#' @param status +#' A sawmill status description. +#' +#' @details +#' The \code{create_status_cols()} function works by initializing the default +#' sawmill status as specified in the \code{check_grain()} function. +#' The `sawmill_pass` column indicates whether sawmill should operate on the +#' resistance outcome. Set `sawmill_pass = FALSE` after other co-occurring +#' events during check failure. +#' +#' @return +#' The passed tibble of timber with additional columns containing the current +#' sawmill status. +#' +#' +#' @export + +create_status_cols <- function(timber, status = "Initialized.") { + # Column 'sawmill_pass' indicates whether sawmill should operate on the + # resistance outcome. Set 'sawmill_pass = FALSE' after other co-occurring + # events during check failure. + if (!('sawmill_pass' %in% names(timber))) { + timber[ , 'sawmill_pass'] <- TRUE + message("Column 'sawmill_pass' did not exist and was created.") + } + + # Column 'sawmill_status' indicates the current sawmill status. + # Set 'sawmill_status' after every sawmill operation. + if (!('sawmill_status' %in% names(timber))) { + # Default status + timber[ , 'sawmill_status'] <- status + message("Column 'sawmill_status' did not exist and was created.") + } + + return(timber) + +} diff --git a/R/validate_contingency_table.R b/R/validate_contingency_table.R index aea9b7c..f1c477f 100644 --- a/R/validate_contingency_table.R +++ b/R/validate_contingency_table.R @@ -86,8 +86,23 @@ validate_contingency_table <- function (.A = NA, .B = NA, table_type = table_type)) } + # Check table type. + if ( !is.na(.A) & !is.na(.C) ) { - status_OK <- "OK: parameters pass checks for contingency table." + table_type <- "con_table_pos_tot" + + } else if ( !is.na(.B) & !is.na(.D) ) { + + table_type <- "con_table_neg_tot" + + } else { + + status <- "Error: could not determine table type." + table_type <- "NA: could not determine table type." + + } + + status <- "OK: parameters pass checks for contingency table." return(list(is_valid = TRUE, status = status, diff --git a/man/create_status_cols.Rd b/man/create_status_cols.Rd new file mode 100644 index 0000000..9ba7966 --- /dev/null +++ b/man/create_status_cols.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/create_status_cols.R +\name{create_status_cols} +\alias{create_status_cols} +\title{Initializes the `sawmill_status` and `sawmill_pass` columns at the start + of the \code{check_grain()} function} +\usage{ +create_status_cols(timber, status = "Initialized.") +} +\arguments{ +\item{timber}{A tibble of timber, with a table built by \code{\link{build_table}}.} + +\item{status}{A sawmill status description.} +} +\value{ +The passed tibble of timber with additional columns containing the current + sawmill status. +} +\description{ +\code{create_status_cols()} adds columns to the passed tibble, containing + the sawmill status provided. +} +\details{ +The \code{create_status_cols()} function works by initializing the default + sawmill status as specified in the \code{check_grain()} function. + The `sawmill_pass` column indicates whether sawmill should operate on the + resistance outcome. Set `sawmill_pass = FALSE` after other co-occurring + events during check failure. +} diff --git a/man/sawmill.Rd b/man/sawmill.Rd index 01d7289..3e2d381 100644 --- a/man/sawmill.Rd +++ b/man/sawmill.Rd @@ -2,9 +2,19 @@ % Please edit documentation in R/sawmill.R \docType{package} \name{sawmill} +\alias{sawmill-package} \alias{sawmill} \title{sawmill: A Package to Process CEDAR Queries} \description{ The \code{sawmill} package is used to process queries exported from CEDAR, herein refered to as \strong{timber}. } +\author{ +\strong{Maintainer}: Brennan Chapman \email{chapmanb@uoguelph.ca} + +Authors: +\itemize{ + \item Charly Phillips +} + +}