This commit is contained in:
Andreas Gammelgaard Damsbo 2024-11-21 14:22:36 +01:00
parent 40d95e41c3
commit ae1c120cd8
No known key found for this signature in database
4 changed files with 30 additions and 16 deletions

View File

@ -50,7 +50,7 @@ file_extension <- function(filenames) {
#' @examples #' @examples
#' read_input("https://raw.githubusercontent.com/agdamsbo/cognitive.index.lookup/main/data/sample.csv") #' read_input("https://raw.githubusercontent.com/agdamsbo/cognitive.index.lookup/main/data/sample.csv")
read_input <- function(file, consider.na = c("NA", '""', "")) { read_input <- function(file, consider.na = c("NA", '""', "")) {
ext <- tools::file_ext(file) ext <- tolower(tools::file_ext(file))
tryCatch( tryCatch(
{ {
@ -66,7 +66,7 @@ read_input <- function(file, consider.na = c("NA", '""', "")) {
df <- readr::read_rds(file = file) df <- readr::read_rds(file = file)
}else { }else {
stop("Input file format has to be on of: 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) { error = function(e) {

View File

@ -12,6 +12,7 @@ GithubActions
JSON JSON
Lifecycle Lifecycle
METACRAN METACRAN
Nav
ORCID ORCID
POSIXct POSIXct
Pivotting Pivotting
@ -19,17 +20,22 @@ README
REDCap REDCap
REDCapR REDCapR
REDCapRITS REDCapRITS
REDCapTidieR
WD WD
al al
api api
attr attr
calc
capitalisation
charater charater
cond cond
cpr
da da
dafault dafault
datadictionary datadictionary
datetime datetime
demonstrational demonstrational
detatched
dir dir
dmy dmy
docx docx
@ -38,6 +44,10 @@ dplyr
ds ds
dta dta
et et
factorises
factorising
fct
forcats
github github
gues gues
hms hms
@ -50,7 +60,9 @@ mRS
matadata matadata
md md
mdy mdy
mrs
mtcars mtcars
na
natively natively
ncol ncol
og og
@ -59,8 +71,10 @@ pegeler
perl perl
pos pos
pre pre
rds
readr readr
realising realising
redcapAPI
renv renv
runApp runApp
sel sel
@ -75,8 +89,12 @@ subheader
textclean textclean
thorugh thorugh
tibble tibble
tidyverse
trinker trinker
truefalse
ui
un
unlabelled
uri uri
vec
wil wil
ymd ymd

View File

@ -5,6 +5,6 @@ account: agdamsbo
server: shinyapps.io server: shinyapps.io
hostUrl: https://api.shinyapps.io/v1 hostUrl: https://api.shinyapps.io/v1
appId: 11351429 appId: 11351429
bundleId: 9392352 bundleId: 9396834
url: https://agdamsbo.shinyapps.io/redcapcast/ url: https://agdamsbo.shinyapps.io/redcapcast/
version: 1 version: 1

View File

@ -17,21 +17,23 @@ server <- function(input, output, session) {
file = NULL file = NULL
) )
dat <- shiny::reactive({ ds <- shiny::reactive({
shiny::req(input$ds) shiny::req(input$ds)
out <- read_input(input$ds$datapath) out <- read_input(input$ds$datapath)
# Saves labels to reapply later
# labels <- lapply(out, get_attr)
out <- out |> out <- out |>
## Parses data with readr functions ## Parses data with readr functions
parse_data() |> 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)) dplyr::mutate(dplyr::across(dplyr::where(is.logical), as_factor))
out
})
dat <- shiny::reactive({
out <- ds()
if (!is.null(input$factor_vars)) { if (!is.null(input$factor_vars)) {
out <- out |> out <- out |>
dplyr::mutate( 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 out
}) })