R/adhere_cleanr.R

Defines functions adhere_cleanr.default adhere_cleanr

Documented in adhere_cleanr adhere_cleanr.default

#' Clean drug adherence data
#'
#' Take drug adherence data from routine TB programmes and clean for
#' further analysis.
#'
#' @param x data frame containing drug adherence data
#' @author Jay Achar
#' @seealso \code{\link{tbcleanr}}
#' @importFrom assertthat assert_that
#' @export

adhere_cleanr <- function(x) {

  # check input
  assert_that(is.data.frame(x))

  # apply useMethod approach
  UseMethod("adhere_cleanr", x)
}


#' Default method for adhere_cleanr()
#'
#' Allow data frames with unspecified object class to pass through
#' @inheritParams adhere_cleanr
#' @author Jay Achar
#' @seealso \code{\link{tbcleanr}}
#' @export

adhere_cleanr.default <- function(x) {

  # check whether adm object class can be applied
  y <- adhere_classr(x)

  # recycle if class sucessfully applied
  if (length(class(y)) > length(class(x))) {

    adhere_cleanr(y)

  } else {

    message("No adherence object class detected: adhere_cleanr() not applied.")
    x
  }


}
JayAchar/tbcleanr documentation built on Aug. 12, 2020, 8:40 a.m.