From ae1c120cd8add44c3c55609b0fec8a3c848a8bf5 Mon Sep 17 00:00:00 2001 From: Andreas Gammelgaard Damsbo Date: Thu, 21 Nov 2024 14:22:36 +0100 Subject: [PATCH] cleaning --- R/shiny_cast.R | 4 ++-- inst/WORDLIST | 20 ++++++++++++++++++- .../shinyapps.io/agdamsbo/redcapcast.dcf | 2 +- inst/shiny-examples/casting/server.R | 20 ++++++++----------- 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/R/shiny_cast.R b/R/shiny_cast.R index 585c34e..08d7d6e 100644 --- a/R/shiny_cast.R +++ b/R/shiny_cast.R @@ -50,7 +50,7 @@ file_extension <- function(filenames) { #' @examples #' read_input("https://raw.githubusercontent.com/agdamsbo/cognitive.index.lookup/main/data/sample.csv") read_input <- function(file, consider.na = c("NA", '""', "")) { - ext <- tools::file_ext(file) + ext <- tolower(tools::file_ext(file)) tryCatch( { @@ -66,7 +66,7 @@ read_input <- function(file, consider.na = c("NA", '""', "")) { df <- readr::read_rds(file = file) }else { stop("Input file format has to be on of: - '.csv', '.xls', '.xlsx', '.dta', '.rds' or '.ods'") + '.csv', '.xls', '.xlsx', '.dta', '.ods' or '.rds'") } }, error = function(e) { diff --git a/inst/WORDLIST b/inst/WORDLIST index a87457a..c3ce7cb 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -12,6 +12,7 @@ GithubActions JSON Lifecycle METACRAN +Nav ORCID POSIXct Pivotting @@ -19,17 +20,22 @@ README REDCap REDCapR REDCapRITS +REDCapTidieR WD al api attr +calc +capitalisation charater cond +cpr da dafault datadictionary datetime demonstrational +detatched dir dmy docx @@ -38,6 +44,10 @@ dplyr ds dta et +factorises +factorising +fct +forcats github gues hms @@ -50,7 +60,9 @@ mRS matadata md mdy +mrs mtcars +na natively ncol og @@ -59,8 +71,10 @@ pegeler perl pos pre +rds readr realising +redcapAPI renv runApp sel @@ -75,8 +89,12 @@ subheader textclean thorugh tibble -tidyverse trinker +truefalse +ui +un +unlabelled uri +vec wil ymd 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 f353f52..4d44f8a 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: 9392352 +bundleId: 9396834 url: https://agdamsbo.shinyapps.io/redcapcast/ version: 1 diff --git a/inst/shiny-examples/casting/server.R b/inst/shiny-examples/casting/server.R index 0fbc6c2..0deb29c 100644 --- a/inst/shiny-examples/casting/server.R +++ b/inst/shiny-examples/casting/server.R @@ -17,21 +17,23 @@ server <- function(input, output, session) { file = NULL ) - dat <- shiny::reactive({ + ds <- shiny::reactive({ shiny::req(input$ds) out <- read_input(input$ds$datapath) - # Saves labels to reapply later - # labels <- lapply(out, get_attr) - out <- out |> ## Parses data with readr functions parse_data() |> - ## Converts logical to factor, which overwrites attributes - ## + ## Converts logical to factor, preserving attributes with own function dplyr::mutate(dplyr::across(dplyr::where(is.logical), as_factor)) + out + }) + + dat <- shiny::reactive({ + out <- ds() + if (!is.null(input$factor_vars)) { out <- out |> dplyr::mutate( @@ -42,12 +44,6 @@ server <- function(input, output, session) { ) } - # Old attributes are appended - # out <- purrr::imap(out,\(.x,.i){ - # set_attr(.x,labels[[.i]]) - # }) |> - # dplyr::bind_cols() - out })