naming and dealing with a dependency issue. ready for first release

This commit is contained in:
Andreas Gammelgaard Damsbo 2024-12-19 15:26:23 +01:00
commit a01f7157b5
No known key found for this signature in database
30 changed files with 664 additions and 1026 deletions

View file

@ -1,7 +1,3 @@
# project.aid::merge_scripts(list.files("R/",full.names = TRUE),dest = here::here("app/functions.R"))
# source(here::here("app/functions.R"))
# source("https://raw.githubusercontent.com/agdamsbo/webResearch/refs/heads/main/app/functions.R")
library(readr)
library(MASS)
@ -19,7 +15,7 @@ library(quarto)
library(here)
library(broom)
library(broom.helpers)
library(REDCapCAST)
# library(REDCapCAST)
library(easystats)
library(patchwork)
library(DHARMa)
@ -32,6 +28,17 @@ if (file.exists(here::here("functions.R"))) {
source(here::here("functions.R"))
}
#' freesearcheR server
#'
#' @param input input
#' @param output output
#' @param session session
#'
#' @returns server
#' @export
#' @importFrom REDCapCAST numchar2fct
#'
#' @examples
server <- function(input, output, session) {
## Listing files in www in session start to keep when ending and removing
## everything else.
@ -68,7 +75,7 @@ server <- function(input, output, session) {
out <- out |>
(\(.x){
suppressWarnings(
REDCapCAST::numchar2fct(.x)
numchar2fct(.x)
)
})()
}

View file

@ -1,7 +1,7 @@
########
#### Current file: /Users/au301842/webResearch/inst/apps/data_analysis_modules/functions.R
#### Current file: /Users/au301842/freesearcheR/inst/apps/data_analysis_modules/functions.R
########
@ -249,6 +249,8 @@ cut.Date <- function(x,breaks,start.on.monday=TRUE,...){
is_any_class <- function(data, class.vec) {
any(class(data) %in% class.vec)
}
@ -685,124 +687,124 @@ plot_histogram <- function(data, column, bins = 30, breaks = NULL, color = "#112
m_datafileUI <- function(id) {
ns <- shiny::NS(id)
shiny::tagList(
shiny::fileInput(
inputId = ns("file"),
label = "Upload a file",
multiple = FALSE,
accept = c(
".csv",
".xlsx",
".xls",
".dta",
".ods",
".rds"
)
),
shiny::h4("Parameter specifications"),
shiny::helpText(shiny::em("Select the desired variables and press 'Submit'")),
shiny::uiOutput(ns("include_vars")),
DT::DTOutput(ns("data_input")),
shiny::actionButton(ns("submit"), "Submit")
)
}
m_datafileServer <- function(id, output.format = "df") {
shiny::moduleServer(id, function(input, output, session, ...) {
ns <- shiny::NS(id)
ds <- shiny::reactive({
REDCapCAST::read_input(input$file$datapath) |> REDCapCAST::parse_data()
})
output$include_vars <- shiny::renderUI({
shiny::req(input$file)
shiny::selectizeInput(
inputId = ns("include_vars"),
selected = NULL,
label = "Covariables to include",
choices = colnames(ds()),
multiple = TRUE
)
})
base_vars <- shiny::reactive({
if (is.null(input$include_vars)) {
out <- colnames(ds())
} else {
out <- input$include_vars
}
out
})
output$data_input <-
DT::renderDT({
shiny::req(input$file)
ds()[base_vars()]
})
shiny::eventReactive(input$submit, {
# shiny::req(input$file)
data <- shiny::isolate({
ds()[base_vars()]
})
file_export(data,
output.format = output.format,
tools::file_path_sans_ext(input$file$name)
)
})
})
}
file_app <- function() {
ui <- shiny::fluidPage(
m_datafileUI("data"),
# DT::DTOutput(outputId = "redcap_prev")
toastui::datagridOutput2(outputId = "redcap_prev")
)
server <- function(input, output, session) {
m_datafileServer("data", output.format = "list")
}
shiny::shinyApp(ui, server)
}
file_app()
tdm_data_upload <- teal::teal_data_module(
ui <- function(id) {
shiny::fluidPage(
m_datafileUI(id)
)
},
server = function(id) {
m_datafileServer(id, output.format = "teal")
}
)
tdm_data_read <- teal::teal_data_module(
ui <- function(id) {
shiny::fluidPage(
m_redcap_readUI(id = "redcap")
)
},
server = function(id) {
moduleServer(
id,
function(input, output, session) {
ns <- session$ns
m_redcap_readServer(id = "redcap", output.format = "teal")
}
)
}
)
########
@ -910,13 +912,14 @@ argsstring2list <- function(string) {
factorize <- function(data, vars) {
if (!is.null(vars)) {
data |>
dplyr::mutate(
dplyr::across(
dplyr::all_of(vars),
REDCapCAST::as_factor
as_factor
)
)
} else {
@ -939,6 +942,18 @@ dummy_Imports <- function() {
}
file_export <- function(data, output.format = c("df", "teal", "list"), filename, ...) {
output.format <- match.arg(output.format)
@ -950,9 +965,9 @@ file_export <- function(data, output.format = c("df", "teal", "list"), filename,
{
assign(name, value |>
dplyr::bind_cols() |>
REDCapCAST::parse_data() |>
REDCapCAST::as_factor() |>
REDCapCAST::numchar2fct())
parse_data() |>
as_factor() |>
numchar2fct())
},
value = data,
name = filename
@ -961,9 +976,9 @@ file_export <- function(data, output.format = c("df", "teal", "list"), filename,
datanames(out) <- filename
} else if (output.format == "df") {
out <- data|>
REDCapCAST::parse_data() |>
REDCapCAST::as_factor() |>
REDCapCAST::numchar2fct()
parse_data() |>
as_factor() |>
numchar2fct()
} else if (output.format == "list") {
out <- list(
data = data,
@ -987,11 +1002,12 @@ file_export <- function(data, output.format = c("df", "teal", "list"), filename,
default_parsing <- function(data){
data |>
REDCapCAST::parse_data() |>
REDCapCAST::as_factor() |>
REDCapCAST::numchar2fct()
parse_data() |>
as_factor() |>
numchar2fct()
}
@ -1102,6 +1118,7 @@ m_redcap_readUI <- function(id, include_title = TRUE) {
m_redcap_readServer <- function(id, output.format = c("df", "teal", "list")) {
output.format <- match.arg(output.format)
@ -1227,7 +1244,7 @@ m_redcap_readServer <- function(id, output.format = c("df", "teal", "list")) {
shiny::req(input$fields)
record_id <- dd()[[1]][1]
redcap_data <- REDCapCAST::read_redcap_tables(
redcap_data <- read_redcap_tables(
uri = input$uri,
token = input$api,
fields = unique(c(record_id, input$fields)),
@ -1236,10 +1253,10 @@ m_redcap_readServer <- function(id, output.format = c("df", "teal", "list")) {
raw_or_label = "both",
filter_logic = input$filter
) |>
REDCapCAST::redcap_wider() |>
redcap_wider() |>
dplyr::select(-dplyr::ends_with("_complete")) |>
dplyr::select(-dplyr::any_of(record_id)) |>
REDCapCAST::suffix2label()
suffix2label()
out_object <- file_export(redcap_data,
output.format = output.format,
@ -1400,6 +1417,7 @@ redcap_app <- function() {
regression_model <- function(data,
@ -1437,7 +1455,7 @@ regression_model <- function(data,
data <- data |>
purrr::map(\(.x){
if (is.character(.x)) {
suppressWarnings(REDCapCAST::as_factor(.x))
suppressWarnings(as_factor(.x))
} else {
.x
}
@ -1691,7 +1709,7 @@ regression_table <- function(x, ...) {
regression_table_create <- function(x, ..., args.list = NULL, fun = "gtsummary::tbl_regression") {
# Stripping custom class
class(x) <- class(x)[class(x) != "webresearch_model"]
class(x) <- class(x)[class(x) != "freesearcher_model"]
if (any(c(length(class(x)) != 1, class(x) != "lm"))) {
if (!"exponentiate" %in% names(args.list)) {
@ -1811,7 +1829,7 @@ modify_qmd <- function(file, format) {
########
#### Current file: R//shiny_webResearch.R
#### Current file: R//shiny_freesearcheR.R
########
@ -1827,18 +1845,16 @@ modify_qmd <- function(file, format) {
shiny_webResearch <- function(data = NULL, ...) {
appDir <- system.file("apps", "data_analysis_modules", package = "webResearch")
shiny_freesearcheR <- function(...) {
appDir <- system.file("apps", "data_analysis_modules", package = "freesearcheR")
if (appDir == "") {
stop("Could not find the app directory. Try re-installing `webResearch`.", call. = FALSE)
stop("Could not find the app directory. Try re-installing `freesearcheR`.", call. = FALSE)
}
G <- .GlobalEnv
if (!is.null(data) && is.data.frame(data)) {
assign("webResearch_data", data, envir = G)
}
a <- shiny::runApp(appDir = appDir, ...)
a <- shiny::runApp(appDir = paste0(appDir,"/app.R"), ...)
return(invisible(a))
}
@ -1885,7 +1901,7 @@ custom_theme <- function(...,
########
#### Current file: /Users/au301842/webResearch/inst/apps/data_analysis_modules/ui.R
#### Current file: /Users/au301842/freesearcheR/inst/apps/data_analysis_modules/ui.R
########
# ns <- NS(id)
@ -2214,7 +2230,7 @@ ui <- bslib::page_fluid(
"Data is only stored for analyses and deleted immediately afterwards."),
shiny::p(
style = "margin: 1; color: #888;",
"Andreas G Damsbo | AGPLv3 license | ", shiny::tags$a("Source on Github", href = "https://github.com/agdamsbo/webResearch/", target="_blank", rel="noopener noreferrer")
"Andreas G Damsbo | AGPLv3 license | ", shiny::tags$a("Source on Github", href = "https://github.com/agdamsbo/freesearcheR/", target="_blank", rel="noopener noreferrer")
),
)
)
@ -2222,14 +2238,9 @@ ui <- bslib::page_fluid(
########
#### Current file: /Users/au301842/webResearch/inst/apps/data_analysis_modules/server.R
#### Current file: /Users/au301842/freesearcheR/inst/apps/data_analysis_modules/server.R
########
# project.aid::merge_scripts(list.files("R/",full.names = TRUE),dest = here::here("app/functions.R"))
# source(here::here("app/functions.R"))
# source("https://raw.githubusercontent.com/agdamsbo/webResearch/refs/heads/main/app/functions.R")
library(readr)
library(MASS)
library(stats)
@ -2246,7 +2257,7 @@ library(quarto)
library(here)
library(broom)
library(broom.helpers)
library(REDCapCAST)
# library(REDCapCAST)
library(easystats)
library(patchwork)
library(DHARMa)
@ -2255,10 +2266,7 @@ library(toastui)
library(IDEAFilter)
library(shinyWidgets)
library(DT)
# if (!requireNamespace("webResearch")) {
# devtools::install_github("agdamsbo/webResearch", quiet = TRUE, upgrade = "never")
# }
# library(webResearch)
# library(freesearcheR)
# source("functions.R")
@ -2269,7 +2277,17 @@ library(DT)
# dark <- custom_theme(bg = "#000",fg="#fff")
#' freesearcheR server
#'
#' @param input input
#' @param output output
#' @param session session
#'
#' @returns server
#' @export
#' @importFrom REDCapCAST fct_drop.data.frame
#'
#' @examples
server <- function(input, output, session) {
## Listing files in www in session start to keep when ending and removing
## everything else.
@ -2308,7 +2326,6 @@ server <- function(input, output, session) {
rv <- shiny::reactiveValues(
list = list(),
ds = NULL,
input = exists("webResearch_data"),
local_temp = NULL,
ready = NULL,
test = "no",
@ -2373,33 +2390,6 @@ server <- function(input, output, session) {
rv$data_original <- from_env$data()
})
# ds <-
# shiny::reactive({
# # input$file1 will be NULL initially. After the user selects
# # and uploads a file, head of that data file by default,
# # or all rows if selected, will be shown.
# # if (v$input) {
# # out <- webResearch_data
# # } else if (input$source == "file") {
# # req(data_file$data())
# # out <- data_file$data()
# # } else if (input$source == "redcap") {
# # req(purrr::pluck(data_redcap(), "data")())
# # out <- purrr::pluck(data_redcap(), "data")()
# # }
#
# req(rv$data_original)
#
# rv$ds <- "loaded"
#
# rv$data <- rv$data_original
#
#
# # rv$data <- rv$data_original
#
# # rv$data_original
# })
##############################################################################
#########
######### Data modification section
@ -2589,7 +2579,7 @@ server <- function(input, output, session) {
{
data <- data_filter() |>
dplyr::mutate(dplyr::across(dplyr::where(is.character), as.factor)) |>
REDCapCAST::fct_drop.data.frame() |>
fct_drop.data.frame() |>
factorize(vars = input$factor_vars)
if (input$strat_var == "none") {
@ -2809,7 +2799,7 @@ server <- function(input, output, session) {
########
#### Current file: /Users/au301842/webResearch/inst/apps/data_analysis_modules/launch.R
#### Current file: /Users/au301842/freesearcheR/inst/apps/data_analysis_modules/launch.R
########
shinyApp(ui, server)

View file

@ -1,8 +1,3 @@
# project.aid::merge_scripts(list.files("R/",full.names = TRUE),dest = here::here("app/functions.R"))
# source(here::here("app/functions.R"))
# source("https://raw.githubusercontent.com/agdamsbo/webResearch/refs/heads/main/app/functions.R")
library(readr)
library(MASS)
library(stats)
@ -19,7 +14,7 @@ library(quarto)
library(here)
library(broom)
library(broom.helpers)
library(REDCapCAST)
# library(REDCapCAST)
library(easystats)
library(patchwork)
library(DHARMa)
@ -28,10 +23,7 @@ library(toastui)
library(IDEAFilter)
library(shinyWidgets)
library(DT)
# if (!requireNamespace("webResearch")) {
# devtools::install_github("agdamsbo/webResearch", quiet = TRUE, upgrade = "never")
# }
# library(webResearch)
# library(freesearcheR)
# source("functions.R")
@ -42,7 +34,17 @@ library(DT)
# dark <- custom_theme(bg = "#000",fg="#fff")
#' freesearcheR server
#'
#' @param input input
#' @param output output
#' @param session session
#'
#' @returns server
#' @export
#' @importFrom REDCapCAST fct_drop.data.frame
#'
#' @examples
server <- function(input, output, session) {
## Listing files in www in session start to keep when ending and removing
## everything else.
@ -81,7 +83,6 @@ server <- function(input, output, session) {
rv <- shiny::reactiveValues(
list = list(),
ds = NULL,
input = exists("webResearch_data"),
local_temp = NULL,
ready = NULL,
test = "no",
@ -146,33 +147,6 @@ server <- function(input, output, session) {
rv$data_original <- from_env$data()
})
# ds <-
# shiny::reactive({
# # input$file1 will be NULL initially. After the user selects
# # and uploads a file, head of that data file by default,
# # or all rows if selected, will be shown.
# # if (v$input) {
# # out <- webResearch_data
# # } else if (input$source == "file") {
# # req(data_file$data())
# # out <- data_file$data()
# # } else if (input$source == "redcap") {
# # req(purrr::pluck(data_redcap(), "data")())
# # out <- purrr::pluck(data_redcap(), "data")()
# # }
#
# req(rv$data_original)
#
# rv$ds <- "loaded"
#
# rv$data <- rv$data_original
#
#
# # rv$data <- rv$data_original
#
# # rv$data_original
# })
##############################################################################
#########
######### Data modification section
@ -362,7 +336,7 @@ server <- function(input, output, session) {
{
data <- data_filter() |>
dplyr::mutate(dplyr::across(dplyr::where(is.character), as.factor)) |>
REDCapCAST::fct_drop.data.frame() |>
fct_drop.data.frame() |>
factorize(vars = input$factor_vars)
if (input$strat_var == "none") {

View file

@ -324,7 +324,7 @@ ui <- bslib::page_fluid(
"Data is only stored for analyses and deleted immediately afterwards."),
shiny::p(
style = "margin: 1; color: #888;",
"Andreas G Damsbo | AGPLv3 license | ", shiny::tags$a("Source on Github", href = "https://github.com/agdamsbo/webResearch/", target="_blank", rel="noopener noreferrer")
"Andreas G Damsbo | AGPLv3 license | ", shiny::tags$a("Source on Github", href = "https://github.com/agdamsbo/freesearcheR/", target="_blank", rel="noopener noreferrer")
),
)
)

View file

@ -40,7 +40,7 @@ margin: 0 0.8em 0.2em -1em; vertical-align: middle;
<p>So glad to see you here! Welcome to test this early concept of a platform to easily explore, manipulate and analyse clinical data.</p>
<p>Below will be a more detailed description of the included features and possibilities, as well as the planned and possible feature additions.</p>
<h2 id="contribute">Contribute</h2>
<p>Contributions are very welcome. If you find anything odd, or you think of features to add or remove, please <a href="https://github.com/agdamsbo/webResearch/issues">share and report on the project page on GitHub</a>.</p>
<p>Contributions are very welcome. If you find anything odd, or you think of features to add or remove, please <a href="https://github.com/agdamsbo/freesearcheR/issues">share and report on the project page on GitHub</a>.</p>
<h2 id="roadmap">Roadmap</h2>
<ul>
<li><p><label><input type="checkbox">Stratified analyses</label></p></li>
@ -58,8 +58,8 @@ margin: 0 0.8em 0.2em -1em; vertical-align: middle;
<li><p><label><input type="checkbox">Plot regression analyses results</label></p></li>
<li><p><label><input type="checkbox">Export modified data</label></p></li>
<li><p><label><input type="checkbox">Include reproducible code for all steps</label></p></li>
<li><p><label><input type="checkbox">Modify factor levels (including naming, order, collapsing, removing)</label></p></li>
<li><p><label><input type="checkbox">More options for date/datetime/time grouping/factoring</label></p></li>
<li><p><label><input type="checkbox" checked><del>Modify factor levels</del> Factor level modification is possible through converting factors to numeric &gt; cutting numeric with desired fixed values. 2024-12-12</label></p></li>
<li><p><label><input type="checkbox" checked>More options for date/datetime/time grouping/factoring. Included weekday and month-only options. 2024-12-12</label></p></li>
</ul>

View file

@ -1,34 +0,0 @@
# Documentation on the freesearcheR platform
Welcome! So glad to see you here! Welcome to test this early concept of a platform to easily explore, manipulate and analyse clinical data.
Below will be a more detailed description of the included features and possibilities, as well as the planned and possible feature additions.
## Roadmap
- [ ] Stratified analyses
- Additional study designs:
- [x] Cross-sectional data analyses
- [ ] Longitudinal data analyses
- [ ] Survival analysis
- More detailed variable browser
- [ ] Add histograms for datadistribution
- [ ] Option to edit labels
- [ ] Plot regression analyses results
- [ ] Export modified data
- [ ] Include reproducible code for all steps
- [ ] Modify factor levels
- [ ] More options for date/datetime/time grouping/factoring

View file

@ -14,7 +14,7 @@ Below will be a more detailed description of the included features and possibili
## Contribute
Contributions are very welcome. If you find anything odd, or you think of features to add or remove, please [share and report on the project page on GitHub](https://github.com/agdamsbo/webResearch/issues).
Contributions are very welcome. If you find anything odd, or you think of features to add or remove, please [share and report on the project page on GitHub](https://github.com/agdamsbo/freesearcheR/issues).
## Roadmap
@ -40,6 +40,6 @@ Contributions are very welcome. If you find anything odd, or you think of featur
- [ ] Include reproducible code for all steps
- [ ] Modify factor levels (including naming, order, collapsing, removing)
- [x] ~~Modify factor levels~~ Factor level modification is possible through converting factors to numeric > cutting numeric with desired fixed values. 2024-12-12
- [ ] More options for date/datetime/time grouping/factoring
- [x] More options for date/datetime/time grouping/factoring. Included weekday and month-only options. 2024-12-12

View file

@ -56,8 +56,8 @@ tm_variable_browser_module <- tm_variable_browser(
filters <- teal::teal_slices()
app_source <- "https://github.com/agdamsbo/webresearch"
gh_issues_page <- "https://github.com/agdamsbo/webresearch/issues"
app_source <- "https://github.com/agdamsbo/freesearcheR"
gh_issues_page <- "https://github.com/agdamsbo/freesearcheR/issues"
header <- tags$span(
style = "display: flex; align-items: center; justify-content: space-between; margin: 10px 0 10px 0;",