diff --git a/NAMESPACE b/NAMESPACE index b709d3f..b09a9ca 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -7,6 +7,8 @@ S3method(as_factor,haven_labelled) S3method(as_factor,labelled) S3method(as_factor,logical) S3method(as_factor,numeric) +S3method(fct_drop,data.frame) +S3method(fct_drop,factor) S3method(process_user_input,character) S3method(process_user_input,data.frame) S3method(process_user_input,default) @@ -34,7 +36,6 @@ export(easy_redcap) export(export_redcap_instrument) export(fct2num) export(fct_drop) -export(fct_drop.data.frame) export(file_extension) export(focused_metadata) export(format_redcap_factor) diff --git a/NEWS.md b/NEWS.md index 65306fe..25183c5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,8 @@ -# REDCapCAST 24.11.4 +# REDCapCAST 24.12.2 + +The newly introduced extension of `forcats::fct_drop()` has been corrected to work as intended as a method. + +# REDCapCAST 24.12.1 This release attempts to solve problems hosting the shiny_cast app, while also implementing functions to preserve as much meta data as possible from the REDCap database when exporting data. diff --git a/R/fct_drop.R b/R/fct_drop.R index a4cea29..6c17e2b 100644 --- a/R/fct_drop.R +++ b/R/fct_drop.R @@ -1,7 +1,7 @@ #' Drop unused levels preserving label data #' #' This extends [forcats::fct_drop()] to natively work across a data.frame and -#' replace [base::droplevels()]. +#' replaces [base::droplevels()]. #' #' @param x Factor to drop unused levels #' @param ... Other arguments passed down to method. @@ -10,13 +10,20 @@ #' @importFrom forcats fct_drop #' @export #' @name fct_drop -NULL +fct_drop <- function(x, ...) { + UseMethod("fct_drop") +} #' @rdname fct_drop #' @export +#' +#' @examples +#' mtcars |> +#' numchar2fct() |> +#' fct_drop() fct_drop.data.frame <- function(x, ...) { purrr::map(x, \(.x){ - if (is.factor(.x)){ + if (is.factor(.x)) { forcats::fct_drop(.x) } else { .x @@ -26,4 +33,13 @@ fct_drop.data.frame <- function(x, ...) { } - +#' @rdname fct_drop +#' @export +#' +#' @examples +#' mtcars |> +#' numchar2fct() |> +#' dplyr::mutate(vs = fct_drop(vs)) +fct_drop.factor <- function(x, ...) { + forcats::fct_drop(f = x, ...) +} diff --git a/REDCapCAST.Rproj b/REDCapCAST.Rproj index 4b56c89..cfc222c 100644 --- a/REDCapCAST.Rproj +++ b/REDCapCAST.Rproj @@ -1,4 +1,5 @@ Version: 1.0 +ProjectId: d97cf790-0785-4be6-9651-e02a4867726b RestoreWorkspace: No SaveWorkspace: No diff --git a/inst/shiny-examples/casting/app.R b/inst/shiny-examples/casting/app.R index 4b30388..d091389 100644 --- a/inst/shiny-examples/casting/app.R +++ b/inst/shiny-examples/casting/app.R @@ -61,6 +61,10 @@ server <- function(input, output, session) { out }) + shiny::eventReactive(input$load_data, { + v$file <- "loaded" + }) + # getData <- reactive({ # if(is.null(input$ds$datapath)) return(NULL) # }) @@ -70,7 +74,7 @@ server <- function(input, output, session) { dd <- shiny::reactive({ shiny::req(input$ds) - v$file <- "loaded" + # v$file <- "loaded" ds2dd_detailed( data = dat(), add.auto.id = input$add_id == "yes", @@ -228,16 +232,17 @@ ui <- ".ods" ) ), - # shiny::actionButton( - # inputId = "load_data", - # label = "Load data", - # icon = shiny::icon("circle-down") - # ), - shiny::helpText("Have a look at the preview panels to validate the data dictionary and imported data."), + shiny::actionButton( + inputId = "options", + label = "Show options", + icon = shiny::icon("wrench") + ), + shiny::helpText("Choose and upload a dataset, then press the button for data modification and options for data download or upload."), # For some odd reason this only unfolds when the preview panel is shown.. # This has been solved by adding an arbitrary button to load data - which was abandoned again shiny::conditionalPanel( - condition = "output.uploaded=='yes'", + # condition = "output.uploaded=='yes'", + condition = "input.options > 0", shiny::radioButtons( inputId = "add_id", label = "Add ID, or use first column?", diff --git a/inst/shiny-examples/casting/rsconnect/shinyapps.io/agdamsbo/redcapcast.dcf b/inst/shiny-examples/casting/rsconnect/shinyapps.io/agdamsbo/redcapcast.dcf index fafb29e..88a2738 100644 --- a/inst/shiny-examples/casting/rsconnect/shinyapps.io/agdamsbo/redcapcast.dcf +++ b/inst/shiny-examples/casting/rsconnect/shinyapps.io/agdamsbo/redcapcast.dcf @@ -5,6 +5,6 @@ account: agdamsbo server: shinyapps.io hostUrl: https://api.shinyapps.io/v1 appId: 11351429 -bundleId: 9425139 +bundleId: 9461113 url: https://agdamsbo.shinyapps.io/redcapcast/ version: 1 diff --git a/man/fct_drop.Rd b/man/fct_drop.Rd index 3e418d7..10504de 100644 --- a/man/fct_drop.Rd +++ b/man/fct_drop.Rd @@ -3,9 +3,14 @@ \name{fct_drop} \alias{fct_drop} \alias{fct_drop.data.frame} +\alias{fct_drop.factor} \title{Drop unused levels preserving label data} \usage{ -fct_drop.data.frame(x, ...) +fct_drop(x, ...) + +\method{fct_drop}{data.frame}(x, ...) + +\method{fct_drop}{factor}(x, ...) } \arguments{ \item{x}{Factor to drop unused levels} @@ -14,5 +19,13 @@ fct_drop.data.frame(x, ...) } \description{ This extends [forcats::fct_drop()] to natively work across a data.frame and -replace [base::droplevels()]. +replaces [base::droplevels()]. +} +\examples{ +mtcars |> + numchar2fct() |> + fct_drop() +mtcars |> + numchar2fct() |> + dplyr::mutate(vs = fct_drop(vs)) } diff --git a/renv.lock b/renv.lock index 8dd685f..d3b01a1 100644 --- a/renv.lock +++ b/renv.lock @@ -187,6 +187,22 @@ ], "Hash": "cd9a672193789068eb5a2aad65a0dedf" }, + "cards": { + "Package": "cards", + "Version": "0.4.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cli", + "dplyr", + "glue", + "rlang", + "tidyr", + "tidyselect" + ], + "Hash": "2cd0d1966092de416f9b7fa1e88b6132" + }, "cellranger": { "Package": "cellranger", "Version": "1.1.0", @@ -456,6 +472,25 @@ ], "Hash": "3170d1f0f45e531c241179ab57cd30bd" }, + "gtsummary": { + "Package": "gtsummary", + "Version": "2.0.3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cards", + "cli", + "dplyr", + "glue", + "gt", + "lifecycle", + "rlang", + "tidyr", + "vctrs" + ], + "Hash": "cd4d593e8ce0ad4e5c2c0acc50ce7330" + }, "haven": { "Package": "haven", "Version": "2.5.4",