feat: loading of local data was internalised based on the datamods package

This commit is contained in:
Andreas Gammelgaard Damsbo 2025-10-02 11:15:40 +02:00
commit 9c1d6ed630
No known key found for this signature in database
11 changed files with 467 additions and 69 deletions

View file

@ -1,5 +1,5 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/regression_model.R
% Please edit documentation in R/helpers.R
\name{data_type}
\alias{data_type}
\title{Data type assessment.}

View file

@ -1,5 +1,5 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/regression_model.R
% Please edit documentation in R/helpers.R
\name{data_types}
\alias{data_types}
\title{Recognised data types from data_type}

21
man/get_data_packages.Rd Normal file
View file

@ -0,0 +1,21 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/import_globalenv-ext.R
\name{get_data_packages}
\alias{get_data_packages}
\title{Get packages containing datasets}
\usage{
get_data_packages()
}
\value{
a character vector of packages names
}
\description{
Get packages containing datasets
}
\examples{
if (interactive()) {
get_data_packages()
}
}

View file

@ -17,7 +17,7 @@ data.frame(See \code{eulerr::euler})}
\item{...}{further arguments passed to eulerr::euler}
}
\description{
THis is slightly modified from https://gist.github.com/danlooo/d23d8bcf8856c7dd8e86266097404ded
This is slightly modified from https://gist.github.com/danlooo/d23d8bcf8856c7dd8e86266097404ded
This functions uses eulerr::euler to plot area proportional venn diagramms
but plots it using ggplot2

50
man/import-globalenv.Rd Normal file
View file

@ -0,0 +1,50 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/import_globalenv-ext.R
\name{import-globalenv}
\alias{import-globalenv}
\alias{import_globalenv_ui}
\alias{import_globalenv_server}
\title{Import data from an Environment}
\usage{
import_globalenv_ui(
id,
globalenv = TRUE,
packages = datamods::get_data_packages(),
title = TRUE
)
import_globalenv_server(
id,
btn_show_data = TRUE,
show_data_in = c("popup", "modal"),
trigger_return = c("button", "change"),
return_class = c("data.frame", "data.table", "tbl_df", "raw"),
reset = reactive(NULL)
)
}
\arguments{
\item{id}{Module's ID.}
\item{globalenv}{Search for data in Global environment.}
\item{packages}{Name of packages in which to search data.}
\item{title}{Module's title, if \code{TRUE} use the default title,
use \code{NULL} for no title or a \code{shiny.tag} for a custom one.}
\item{btn_show_data}{Display or not a button to display data in a modal window if import is successful.}
\item{show_data_in}{Where to display data: in a \code{"popup"} or in a \code{"modal"} window.}
\item{trigger_return}{When to update selected data:
\code{"button"} (when user click on button) or
\code{"change"} (each time user select a dataset in the list).}
\item{return_class}{Class of returned data: \code{data.frame}, \code{data.table}, \code{tbl_df} (tibble) or \code{raw}.}
\item{reset}{A \code{reactive} function that when triggered resets the data.}
}
\description{
Let the user select a dataset from its own environment or from a package's environment.
Modified from datamods
}

21
man/list_pkg_data.Rd Normal file
View file

@ -0,0 +1,21 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/import_globalenv-ext.R
\name{list_pkg_data}
\alias{list_pkg_data}
\title{List dataset contained in a package}
\usage{
list_pkg_data(pkg)
}
\arguments{
\item{pkg}{Name of the package, must be installed.}
}
\value{
a \code{character} vector or \code{NULL}.
}
\description{
List dataset contained in a package
}
\examples{
list_pkg_data("ggplot2")
}

View file

@ -32,4 +32,19 @@ data.frame(
) |> plot_euler("A", c("B", "C"), "D", seed = 4)
mtcars |> plot_euler("vs", "am", seed = 1)
mtcars |> plot_euler("vs", "am", "cyl", seed = 1)
stRoke::trial |>
dplyr::mutate(
mfi_cut = cut(mfi_6, c(0, 12, max(mfi_6, na.rm = TRUE))),
mdi_cut = cut(mdi_6, c(0, 20, max(mdi_6, na.rm = TRUE)))
) |>
purrr::map2(
c(sapply(stRoke::trial, \(.x)REDCapCAST::get_attr(.x, attr = "label")), "Fatigue", "Depression"),
\(.x, .y){
REDCapCAST::set_attr(.x, .y, "label")
}
) |>
dplyr::bind_cols() |>
plot_euler("mfi_cut", "mdi_cut")
stRoke::trial |>
plot_euler(pri="male", sec=c("hypertension"))
}

View file

@ -82,36 +82,4 @@ list(
purrr::map(regression_table) |>
tbl_merge()
}
regression_table <- function(x, ...) {
UseMethod("regression_table")
}
#' @rdname regression_table
#' @export
regression_table.list <- function(x, ...) {
x |>
purrr::map(\(.m){
regression_table(x = .m, ...) |>
gtsummary::add_n()
}) |>
gtsummary::tbl_stack()
}
#' @rdname regression_table
#' @export
regression_table.default <- function(x, ..., args.list = NULL, fun = "gtsummary::tbl_regression") {
# Stripping custom class
class(x) <- class(x)[class(x) != "freesearchr_model"]
if (any(c(length(class(x)) != 1, class(x) != "lm"))) {
if (!"exponentiate" \%in\% names(args.list)) {
args.list <- c(args.list, list(exponentiate = TRUE))
}
}
out <- do.call(getfun(fun), c(list(x = x), args.list))
out |>
gtsummary::add_glance_source_note() # |>
# gtsummary::bold_p()
}
}