From c4b5a7ba7908602288370fdca474bf553446dde5 Mon Sep 17 00:00:00 2001 From: Andreas Gammelgaard Damsbo Date: Wed, 19 Feb 2025 13:17:16 +0100 Subject: [PATCH] updated docs --- NAMESPACE | 16 +++++ R/correlations-module.R | 2 +- R/regression_model.R | 19 ++---- R/shiny_freesearcheR.R | 12 ++++ man/clean_date.Rd | 17 +++++ man/clean_sep.Rd | 21 ++++++ man/data-correlations.Rd | 31 +++++++++ man/data-summary.Rd | 6 +- man/get_fun_options.Rd | 27 ++++++++ man/gg_theme_export.Rd | 17 +++++ man/gg_theme_shiny.Rd | 17 +++++ man/launch.Rd | 17 +++++ man/merge_long.Rd | 19 ++++++ man/outcome_type.Rd | 22 +++++++ man/plot.tbl_regression.Rd | 29 +++++++++ man/possible_functions.Rd | 28 ++++++++ man/regression_model.Rd | 129 +++++++++++++++++++++++++++++++++---- man/regression_model_uv.Rd | 51 --------------- man/regression_table.Rd | 4 +- man/remove_empty_cols.Rd | 22 +++++++ man/supported_functions.Rd | 18 ++++++ 21 files changed, 444 insertions(+), 80 deletions(-) create mode 100644 man/clean_date.Rd create mode 100644 man/clean_sep.Rd create mode 100644 man/data-correlations.Rd create mode 100644 man/get_fun_options.Rd create mode 100644 man/gg_theme_export.Rd create mode 100644 man/gg_theme_shiny.Rd create mode 100644 man/launch.Rd create mode 100644 man/merge_long.Rd create mode 100644 man/outcome_type.Rd create mode 100644 man/plot.tbl_regression.Rd create mode 100644 man/possible_functions.Rd delete mode 100644 man/regression_model_uv.Rd create mode 100644 man/remove_empty_cols.Rd create mode 100644 man/supported_functions.Rd diff --git a/NAMESPACE b/NAMESPACE index 20aa3d7..ee1dcc4 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,14 +1,19 @@ # Generated by roxygen2: do not edit by hand S3method(cut,hms) +S3method(plot,tbl_regression) export(add_class_icon) export(add_sparkline) export(argsstring2list) export(baseline_table) +export(clean_date) +export(clean_sep) export(create_overview_datagrid) export(custom_theme) export(cut_variable_server) export(cut_variable_ui) +export(data_correlations_server) +export(data_correlations_ui) export(data_summary_server) export(data_summary_ui) export(default_format_arguments) @@ -16,24 +21,35 @@ export(default_parsing) export(factorize) export(file_export) export(format_writer) +export(get_fun_options) export(getfun) +export(gg_theme_export) +export(gg_theme_shiny) export(index_embed) export(is_any_class) export(is_consecutive) export(is_datetime) +export(launch) export(m_datafileUI) export(m_redcap_readServer) export(m_redcap_readUI) +export(merge_long) export(modal_cut_variable) export(modify_qmd) +export(outcome_type) export(overview_vars) +export(possible_functions) export(read_input) export(regression_model) +export(regression_model_list) export(regression_model_uv) +export(regression_model_uv_list) export(regression_table) +export(remove_empty_cols) export(remove_na_attr) export(shiny_freesearcheR) export(specify_qmd_format) +export(supported_functions) export(tbl_merge) export(update_variables_server) export(update_variables_ui) diff --git a/R/correlations-module.R b/R/correlations-module.R index 0063c78..bd35118 100644 --- a/R/correlations-module.R +++ b/R/correlations-module.R @@ -6,7 +6,7 @@ #' @returns Shiny ui module #' @export data_correlations_ui <- function(id, ...) { - ns <- NS(id) + ns <- shiny::NS(id) shiny::tagList( shiny::textOutput(outputId = ns("suggest")), diff --git a/R/regression_model.R b/R/regression_model.R index ce79b0e..eda2bf4 100644 --- a/R/regression_model.R +++ b/R/regression_model.R @@ -13,6 +13,7 @@ #' #' @return object of standard class for fun #' @export +#' @rdname regression_model #' #' @examples #' gtsummary::trial |> @@ -149,6 +150,7 @@ regression_model <- function(data, #' @param ... ignored for now #' #' @importFrom stats as.formula +#' @rdname regression_model #' #' @return object of standard class for fun #' @export @@ -323,7 +325,7 @@ supported_functions <- function() { #' #' @param data data #' -#' @returns +#' @returns character vector #' @export #' #' @examples @@ -412,8 +414,9 @@ get_fun_options <- function(data) { #' argsstring2list() or list of arguments. Default is NULL. #' @param ... ignored #' -#' @returns +#' @returns list #' @export +#' @rdname regression_model #' #' @examples #' \dontrun{ @@ -528,19 +531,9 @@ list2str <- function(data) { } -#' Title -#' -#' @param data -#' @param outcome.str -#' @param fun.descr -#' @param fun -#' @param formula.str -#' @param args.list -#' @param vars -#' @param ... -#' #' @returns list #' @export +#' @rdname regression_model #' #' @examples #' \dontrun{ diff --git a/R/shiny_freesearcheR.R b/R/shiny_freesearcheR.R index 033ea00..9a2095e 100644 --- a/R/shiny_freesearcheR.R +++ b/R/shiny_freesearcheR.R @@ -23,3 +23,15 @@ shiny_freesearcheR <- function(...) { a <- shiny::runApp(appDir = paste0(appDir,"/app.R"), ...) return(invisible(a)) } + + +#' Easily launch the freesearcheR app +#' +#' @param ... passed on to `shiny::runApp()` +#' +#' @returns shiny app +#' @export +#' +launch <- function(...){ + shiny_freesearcheR(...) +} diff --git a/man/clean_date.Rd b/man/clean_date.Rd new file mode 100644 index 0000000..fb1354f --- /dev/null +++ b/man/clean_date.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/update-variables-ext.R +\name{clean_date} +\alias{clean_date} +\title{Attempts at applying uniform date format} +\usage{ +clean_date(data) +} +\arguments{ +\item{data}{character string vector of possible dates} +} +\value{ +character string +} +\description{ +Attempts at applying uniform date format +} diff --git a/man/clean_sep.Rd b/man/clean_sep.Rd new file mode 100644 index 0000000..b80113f --- /dev/null +++ b/man/clean_sep.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/update-variables-ext.R +\name{clean_sep} +\alias{clean_sep} +\title{gsub wrapper for piping with default values for separator substituting} +\usage{ +clean_sep(data, old.sep = "[-.,/]", new.sep = "-") +} +\arguments{ +\item{data}{character vector} + +\item{old.sep}{old separator} + +\item{new.sep}{new separator} +} +\value{ +character vector +} +\description{ +gsub wrapper for piping with default values for separator substituting +} diff --git a/man/data-correlations.Rd b/man/data-correlations.Rd new file mode 100644 index 0000000..df65126 --- /dev/null +++ b/man/data-correlations.Rd @@ -0,0 +1,31 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/correlations-module.R +\name{data-correlations} +\alias{data-correlations} +\alias{data_correlations_ui} +\alias{data_correlations_server} +\title{Data correlations evaluation module} +\usage{ +data_correlations_ui(id, ...) + +data_correlations_server(id, data, include.class = NULL, cutoff = 0.7, ...) +} +\arguments{ +\item{id}{Module id. (Use 'ns("id")')} + +\item{...}{arguments passed to toastui::datagrid} + +\item{data}{data} + +\item{color.main}{main color} + +\item{color.sec}{secondary color} +} +\value{ +Shiny ui module + +shiny server module +} +\description{ +Data correlations evaluation module +} diff --git a/man/data-summary.Rd b/man/data-summary.Rd index 7d0e8fb..6e9ecc9 100644 --- a/man/data-summary.Rd +++ b/man/data-summary.Rd @@ -8,16 +8,18 @@ \usage{ data_summary_ui(id) -data_summary_server(id, data, color.main, color.sec) +data_summary_server(id, data, color.main, color.sec, ...) } \arguments{ -\item{id}{id} +\item{id}{Module id. (Use 'ns("id")')} \item{data}{data} \item{color.main}{main color} \item{color.sec}{secondary color} + +\item{...}{arguments passed to toastui::datagrid} } \value{ Shiny ui module diff --git a/man/get_fun_options.Rd b/man/get_fun_options.Rd new file mode 100644 index 0000000..9b27b14 --- /dev/null +++ b/man/get_fun_options.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/regression_model.R +\name{get_fun_options} +\alias{get_fun_options} +\title{Get the function options based on the selected function description} +\usage{ +get_fun_options(data) +} +\arguments{ +\item{data}{vector} +} +\value{ +list +} +\description{ +Get the function options based on the selected function description +} +\examples{ +mtcars |> + default_parsing() |> + dplyr::pull(mpg) |> + possible_functions(design = "cross-sectional") |> + (\(.x){ + .x[[1]] + })() |> + get_fun_options() +} diff --git a/man/gg_theme_export.Rd b/man/gg_theme_export.Rd new file mode 100644 index 0000000..c8a220c --- /dev/null +++ b/man/gg_theme_export.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/theme.R +\name{gg_theme_export} +\alias{gg_theme_export} +\title{GGplot default theme for plotting export objects} +\usage{ +gg_theme_export() +} +\arguments{ +\item{data}{ggplot object} +} +\value{ +ggplot object +} +\description{ +GGplot default theme for plotting export objects +} diff --git a/man/gg_theme_shiny.Rd b/man/gg_theme_shiny.Rd new file mode 100644 index 0000000..6d19d6b --- /dev/null +++ b/man/gg_theme_shiny.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/theme.R +\name{gg_theme_shiny} +\alias{gg_theme_shiny} +\title{GGplot default theme for plotting in Shiny} +\usage{ +gg_theme_shiny() +} +\arguments{ +\item{data}{ggplot object} +} +\value{ +ggplot object +} +\description{ +GGplot default theme for plotting in Shiny +} diff --git a/man/launch.Rd b/man/launch.Rd new file mode 100644 index 0000000..0d427e8 --- /dev/null +++ b/man/launch.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/shiny_freesearcheR.R +\name{launch} +\alias{launch} +\title{Easily launch the freesearcheR app} +\usage{ +launch(...) +} +\arguments{ +\item{...}{passed on to \code{shiny::runApp()}} +} +\value{ +shiny app +} +\description{ +Easily launch the freesearcheR app +} diff --git a/man/merge_long.Rd b/man/merge_long.Rd new file mode 100644 index 0000000..ea58df1 --- /dev/null +++ b/man/merge_long.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/regression_plot.R +\name{merge_long} +\alias{merge_long} +\title{Wrapper to pivot gtsummary table data to long for plotting} +\usage{ +merge_long(list, model.names) +} +\arguments{ +\item{list}{a custom regression models list} + +\item{model.names}{names of models to include} +} +\value{ +list +} +\description{ +Wrapper to pivot gtsummary table data to long for plotting +} diff --git a/man/outcome_type.Rd b/man/outcome_type.Rd new file mode 100644 index 0000000..6a674da --- /dev/null +++ b/man/outcome_type.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/regression_model.R +\name{outcome_type} +\alias{outcome_type} +\title{Outcome data type assessment} +\usage{ +outcome_type(data) +} +\arguments{ +\item{data}{data} +} +\value{ +outcome type +} +\description{ +Outcome data type assessment +} +\examples{ +mtcars |> + default_parsing() |> + lapply(outcome_type) +} diff --git a/man/plot.tbl_regression.Rd b/man/plot.tbl_regression.Rd new file mode 100644 index 0000000..3c5d7db --- /dev/null +++ b/man/plot.tbl_regression.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/regression_plot.R +\name{plot.tbl_regression} +\alias{plot.tbl_regression} +\title{Regression coef plot from gtsummary. Slightly modified to pass on arguments} +\usage{ +\method{plot}{tbl_regression}(x, ...) +} +\arguments{ +\item{x}{(\code{tbl_regression}, \code{tbl_uvregression})\cr +A 'tbl_regression' or 'tbl_uvregression' object} + +\item{...}{arguments passed to \code{ggstats::ggcoef_plot(...)}} +} +\value{ +ggplot object +} +\description{ +Regression coef plot from gtsummary. Slightly modified to pass on arguments +} +\examples{ +\dontrun{ +mod <- lm(mpg ~ ., mtcars) +p <- mod |> + gtsummary::tbl_regression() |> + plot(colour = "variable") +} + +} diff --git a/man/possible_functions.Rd b/man/possible_functions.Rd new file mode 100644 index 0000000..9dbd6de --- /dev/null +++ b/man/possible_functions.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/regression_model.R +\name{possible_functions} +\alias{possible_functions} +\title{Get possible regression models} +\usage{ +possible_functions(data, design = c("cross-sectional")) +} +\arguments{ +\item{data}{data} +} +\value{ +character vector +} +\description{ +Get possible regression models +} +\examples{ +mtcars |> + default_parsing() |> + dplyr::pull("cyl") |> + possible_functions(design = "cross-sectional") + +mtcars |> + default_parsing() |> + dplyr::select("cyl") |> + possible_functions(design = "cross-sectional") +} diff --git a/man/regression_model.Rd b/man/regression_model.Rd index 8e23d20..049e24d 100644 --- a/man/regression_model.Rd +++ b/man/regression_model.Rd @@ -2,41 +2,85 @@ % Please edit documentation in R/regression_model.R \name{regression_model} \alias{regression_model} +\alias{regression_model_uv} +\alias{regression_model_list} +\alias{regression_model_uv_list} \title{Create a regression model programatically} \usage{ regression_model( data, outcome.str, - auto.mode = TRUE, + auto.mode = FALSE, formula.str = NULL, args.list = NULL, fun = NULL, vars = NULL, ... ) + +regression_model_uv( + data, + outcome.str, + args.list = NULL, + fun = NULL, + vars = NULL, + ... +) + +regression_model_list( + data, + outcome.str, + fun.descr, + fun = NULL, + formula.str = NULL, + args.list = NULL, + vars = NULL, + ... +) + +regression_model_uv_list( + data, + outcome.str, + fun.descr, + fun = NULL, + formula.str = NULL, + args.list = NULL, + vars = NULL, + ... +) } \arguments{ -\item{data}{data set} +\item{data}{data} -\item{outcome.str}{Name of outcome variable. Character vector.} +\item{outcome.str}{name of outcome variable} \item{auto.mode}{Make assumptions on function dependent on outcome data format. Overwrites other arguments.} -\item{formula.str}{Formula as string. Passed through 'glue::glue'. If given, 'outcome.str' and 'vars' are ignored. Optional.} +\item{formula.str}{custom formula glue string. Default is NULL.} -\item{args.list}{List of arguments passed to 'fun' with 'do.call'.} +\item{args.list}{custom character string to be converted using +argsstring2list() or list of arguments. Default is NULL.} -\item{fun}{Name of function as character vector or function to use for model creation.} +\item{fun}{name of custom function. Default is NULL.} \item{vars}{character vector of variables to include} -\item{...}{ignored for now} +\item{...}{ignored} + +\item{fun.descr}{Description of chosen function matching description in +"supported_functions()"} } \value{ object of standard class for fun + +object of standard class for fun + +list + +list } \description{ -Create a regression model programatically +Output is a concatenated list of model information and model } \examples{ gtsummary::trial |> @@ -49,10 +93,73 @@ gtsummary::trial |> formula.str = "{outcome.str}~.", args.list = NULL ) -gtsummary::trial |> regression_model( +gtsummary::trial |> + default_parsing() |> + regression_model( + outcome.str = "trt", + auto.mode = FALSE, + fun = "stats::glm", + args.list = list(family = binomial(link = "logit")) + ) +m <- mtcars |> + default_parsing() |> + regression_model( + outcome.str = "mpg", + auto.mode = FALSE, + fun = "stats::lm", + formula.str = "{outcome.str}~{paste(vars,collapse='+')}", + args.list = NULL, + vars = c("mpg", "cyl") + ) + broom::tidy(m) +\dontrun{ +gtsummary::trial |> + regression_model_uv(outcome.str = "age") +gtsummary::trial |> + regression_model_uv( + outcome.str = "age", + fun = "stats::lm", + args.list = NULL + ) +m <- gtsummary::trial |> regression_model_uv( outcome.str = "trt", - auto.mode = FALSE, fun = "stats::glm", - args.list = list(family = binomial(link = "logit")) + args.list = list(family = stats::binomial(link = "logit")) ) +lapply(m,broom::tidy) |> dplyr::bind_rows() +} +\dontrun{ +gtsummary::trial |> + regression_model( + outcome.str = "age", + fun = "stats::lm", + formula.str = "{outcome.str}~.", + args.list = NULL + ) +ls <- regression_model_list(data = default_parsing(mtcars), outcome.str = "cyl", fun.descr = "Ordinal logistic regression model") +summary(ls$model) + +ls <- regression_model_list(data = default_parsing(gtsummary::trial), outcome.str = "trt", fun.descr = "Logistic regression model") +tbl <- gtsummary::tbl_regression(ls$model, exponentiate = TRUE) +m <- gtsummary::trial |> + default_parsing() |> + regression_model( + outcome.str = "trt", + fun = "stats::glm", + formula.str = "{outcome.str}~.", + args.list = list(family = stats::binomial(link = "logit")) + ) +tbl2 <- gtsummary::tbl_regression(m, exponentiate = TRUE) +broom::tidy(ls$model) +broom::tidy(m) +} +\dontrun{ +gtsummary::trial |> regression_model_uv( + outcome.str = "trt", + fun = "stats::glm", + args.list = list(family = stats::binomial(link = "logit")) +) |> lapply(broom::tidy) |> dplyr::bind_rows() +ms <- regression_model_uv_list(data = default_parsing(mtcars), outcome.str = "mpg", fun.descr = "Linear regression model") +lapply(ms$model,broom::tidy) |> dplyr::bind_rows() +} } diff --git a/man/regression_model_uv.Rd b/man/regression_model_uv.Rd deleted file mode 100644 index 24cbb41..0000000 --- a/man/regression_model_uv.Rd +++ /dev/null @@ -1,51 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/regression_model.R -\name{regression_model_uv} -\alias{regression_model_uv} -\title{Create a regression model programatically} -\usage{ -regression_model_uv( - data, - outcome.str, - args.list = NULL, - fun = NULL, - vars = NULL, - ... -) -} -\arguments{ -\item{data}{data set} - -\item{outcome.str}{Name of outcome variable. Character vector.} - -\item{args.list}{List of arguments passed to 'fun' with 'do.call'.} - -\item{fun}{Name of function as character vector or function to use for model creation.} - -\item{vars}{character vector of variables to include} - -\item{...}{ignored for now} -} -\value{ -object of standard class for fun -} -\description{ -Create a regression model programatically -} -\examples{ -\dontrun{ -gtsummary::trial |> - regression_model_uv(outcome.str = "age") -gtsummary::trial |> - regression_model_uv( - outcome.str = "age", - fun = "stats::lm", - args.list = NULL - ) -gtsummary::trial |> regression_model_uv( - outcome.str = "trt", - fun = "stats::glm", - args.list = list(family = stats::binomial(link = "logit")) -) -} -} diff --git a/man/regression_table.Rd b/man/regression_table.Rd index 946fc8a..1fdc188 100644 --- a/man/regression_table.Rd +++ b/man/regression_table.Rd @@ -23,7 +23,7 @@ Create table of regression model } \examples{ \dontrun{ -gtsummary::trial |> +tbl <- gtsummary::trial |> regression_model( outcome.str = "stage", fun = "MASS::polr" @@ -36,7 +36,7 @@ gtsummary::trial |> formula.str = "{outcome.str}~.", args.list = NULL ) |> - regression_table() + regression_table() |> plot() gtsummary::trial |> regression_model( outcome.str = "trt", diff --git a/man/remove_empty_cols.Rd b/man/remove_empty_cols.Rd new file mode 100644 index 0000000..690a7c9 --- /dev/null +++ b/man/remove_empty_cols.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/helpers.R +\name{remove_empty_cols} +\alias{remove_empty_cols} +\title{Removes columns with completenes below cutoff} +\usage{ +remove_empty_cols(data, cutoff = 0.7) +} +\arguments{ +\item{data}{data frame} + +\item{cutoff}{numeric} +} +\value{ +data frame +} +\description{ +Removes columns with completenes below cutoff +} +\examples{ +data.frame(a=1:10,b=NA, c=c(2,NA)) |> remove_empty_cols(cutoff=.5) +} diff --git a/man/supported_functions.Rd b/man/supported_functions.Rd new file mode 100644 index 0000000..cf78c2a --- /dev/null +++ b/man/supported_functions.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/regression_model.R +\name{supported_functions} +\alias{supported_functions} +\title{Implemented functions} +\usage{ +supported_functions() +} +\value{ +list +} +\description{ +Library of supported functions. The list name and "descr" element should be +unique for each element on list. +} +\examples{ +supported_functions() +}