sbalci/ClinicoPathJamoviModule

View on GitHub
R/jjdotplotstats.h.R

Summary

Maintainability
Test Coverage

# This file is automatically generated, you probably don't want to edit this

jjdotplotstatsOptions <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
    "jjdotplotstatsOptions",
    inherit = jmvcore::Options,
    public = list(
        initialize = function(
            dep = NULL,
            group = NULL,
            grvar = NULL,
            typestatistics = "parametric",
            effsizetype = "biased",
            centralityplotting = FALSE,
            centralitytype = "parameteric",
            mytitle = "",
            xtitle = "",
            ytitle = "",
            originaltheme = FALSE,
            resultssubtitle = TRUE, ...) {

            super$initialize(
                package="ClinicoPath",
                name="jjdotplotstats",
                requiresData=TRUE,
                ...)

            private$..dep <- jmvcore::OptionVariable$new(
                "dep",
                dep,
                suggested=list(
                    "continuous"),
                permitted=list(
                    "numeric"))
            private$..group <- jmvcore::OptionVariable$new(
                "group",
                group,
                suggested=list(
                    "ordinal",
                    "nominal"),
                permitted=list(
                    "factor"))
            private$..grvar <- jmvcore::OptionVariable$new(
                "grvar",
                grvar,
                suggested=list(
                    "ordinal",
                    "nominal"),
                permitted=list(
                    "factor"))
            private$..typestatistics <- jmvcore::OptionList$new(
                "typestatistics",
                typestatistics,
                options=list(
                    "parametric",
                    "nonparametric",
                    "robust",
                    "bayes"),
                default="parametric")
            private$..effsizetype <- jmvcore::OptionList$new(
                "effsizetype",
                effsizetype,
                options=list(
                    "biased",
                    "unbiased",
                    "eta",
                    "omega"),
                default="biased")
            private$..centralityplotting <- jmvcore::OptionBool$new(
                "centralityplotting",
                centralityplotting,
                default=FALSE)
            private$..centralitytype <- jmvcore::OptionList$new(
                "centralitytype",
                centralitytype,
                options=list(
                    "parameteric",
                    "nonparametric",
                    "robust",
                    "bayes"),
                default="parameteric")
            private$..mytitle <- jmvcore::OptionString$new(
                "mytitle",
                mytitle,
                default="")
            private$..xtitle <- jmvcore::OptionString$new(
                "xtitle",
                xtitle,
                default="")
            private$..ytitle <- jmvcore::OptionString$new(
                "ytitle",
                ytitle,
                default="")
            private$..originaltheme <- jmvcore::OptionBool$new(
                "originaltheme",
                originaltheme,
                default=FALSE)
            private$..resultssubtitle <- jmvcore::OptionBool$new(
                "resultssubtitle",
                resultssubtitle,
                default=TRUE)

            self$.addOption(private$..dep)
            self$.addOption(private$..group)
            self$.addOption(private$..grvar)
            self$.addOption(private$..typestatistics)
            self$.addOption(private$..effsizetype)
            self$.addOption(private$..centralityplotting)
            self$.addOption(private$..centralitytype)
            self$.addOption(private$..mytitle)
            self$.addOption(private$..xtitle)
            self$.addOption(private$..ytitle)
            self$.addOption(private$..originaltheme)
            self$.addOption(private$..resultssubtitle)
        }),
    active = list(
        dep = function() private$..dep$value,
        group = function() private$..group$value,
        grvar = function() private$..grvar$value,
        typestatistics = function() private$..typestatistics$value,
        effsizetype = function() private$..effsizetype$value,
        centralityplotting = function() private$..centralityplotting$value,
        centralitytype = function() private$..centralitytype$value,
        mytitle = function() private$..mytitle$value,
        xtitle = function() private$..xtitle$value,
        ytitle = function() private$..ytitle$value,
        originaltheme = function() private$..originaltheme$value,
        resultssubtitle = function() private$..resultssubtitle$value),
    private = list(
        ..dep = NA,
        ..group = NA,
        ..grvar = NA,
        ..typestatistics = NA,
        ..effsizetype = NA,
        ..centralityplotting = NA,
        ..centralitytype = NA,
        ..mytitle = NA,
        ..xtitle = NA,
        ..ytitle = NA,
        ..originaltheme = NA,
        ..resultssubtitle = NA)
)

jjdotplotstatsResults <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
    "jjdotplotstatsResults",
    inherit = jmvcore::Group,
    active = list(
        todo = function() private$.items[["todo"]],
        plot2 = function() private$.items[["plot2"]],
        plot = function() private$.items[["plot"]]),
    private = list(),
    public=list(
        initialize=function(options) {
            super$initialize(
                options=options,
                name="",
                title="Dot Chart",
                refs=list(
                    "ggplot2",
                    "ggstatsplot",
                    "ClinicoPathJamoviModule"),
                clearWith=list(
                    "dep",
                    "group",
                    "grvar",
                    "excl",
                    "originaltheme",
                    "typestatistics"))
            self$add(jmvcore::Html$new(
                options=options,
                name="todo",
                title="To Do"))
            self$add(jmvcore::Image$new(
                options=options,
                name="plot2",
                title="`${group} - {dep} by {grvar}`",
                width=800,
                height=300,
                renderFun=".plot2",
                requiresData=TRUE,
                visible="(grvar)"))
            self$add(jmvcore::Image$new(
                options=options,
                name="plot",
                title="`${group} - {dep}`",
                width=400,
                height=300,
                renderFun=".plot",
                requiresData=TRUE))}))

jjdotplotstatsBase <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
    "jjdotplotstatsBase",
    inherit = jmvcore::Analysis,
    public = list(
        initialize = function(options, data=NULL, datasetId="", analysisId="", revision=0) {
            super$initialize(
                package = "ClinicoPath",
                name = "jjdotplotstats",
                version = c(1,0,0),
                options = options,
                results = jjdotplotstatsResults$new(options=options),
                data = data,
                datasetId = datasetId,
                analysisId = analysisId,
                revision = revision,
                pause = NULL,
                completeWhenFilled = FALSE,
                requiresMissings = FALSE,
                weightsSupport = 'auto')
        }))

#' Dot Chart
#'
#' 
#'
#' @examples
#' \dontrun{
#' # example will be added
#'}
#' @param data The data as a data frame.
#' @param dep .
#' @param group .
#' @param grvar .
#' @param typestatistics .
#' @param effsizetype .
#' @param centralityplotting .
#' @param centralitytype .
#' @param mytitle .
#' @param xtitle .
#' @param ytitle .
#' @param originaltheme .
#' @param resultssubtitle .
#' @return A results object containing:
#' \tabular{llllll}{
#'   \code{results$todo} \tab \tab \tab \tab \tab a html \cr
#'   \code{results$plot2} \tab \tab \tab \tab \tab an image \cr
#'   \code{results$plot} \tab \tab \tab \tab \tab an image \cr
#' }
#'
#' @export
jjdotplotstats <- function(
    data,
    dep,
    group,
    grvar,
    typestatistics = "parametric",
    effsizetype = "biased",
    centralityplotting = FALSE,
    centralitytype = "parameteric",
    mytitle = "",
    xtitle = "",
    ytitle = "",
    originaltheme = FALSE,
    resultssubtitle = TRUE) {

    if ( ! requireNamespace("jmvcore", quietly=TRUE))
        stop("jjdotplotstats requires jmvcore to be installed (restart may be required)")

    if ( ! missing(dep)) dep <- jmvcore::resolveQuo(jmvcore::enquo(dep))
    if ( ! missing(group)) group <- jmvcore::resolveQuo(jmvcore::enquo(group))
    if ( ! missing(grvar)) grvar <- jmvcore::resolveQuo(jmvcore::enquo(grvar))
    if (missing(data))
        data <- jmvcore::marshalData(
            parent.frame(),
            `if`( ! missing(dep), dep, NULL),
            `if`( ! missing(group), group, NULL),
            `if`( ! missing(grvar), grvar, NULL))

    for (v in group) if (v %in% names(data)) data[[v]] <- as.factor(data[[v]])
    for (v in grvar) if (v %in% names(data)) data[[v]] <- as.factor(data[[v]])

    options <- jjdotplotstatsOptions$new(
        dep = dep,
        group = group,
        grvar = grvar,
        typestatistics = typestatistics,
        effsizetype = effsizetype,
        centralityplotting = centralityplotting,
        centralitytype = centralitytype,
        mytitle = mytitle,
        xtitle = xtitle,
        ytitle = ytitle,
        originaltheme = originaltheme,
        resultssubtitle = resultssubtitle)

    analysis <- jjdotplotstatsClass$new(
        options = options,
        data = data)

    analysis$run()

    analysis$results
}