From d1425aaac0d1e6082bb171960a562666a2052350 Mon Sep 17 00:00:00 2001 From: Andreas Gammelgaard Damsbo Date: Wed, 27 Nov 2024 09:54:38 +0100 Subject: [PATCH] adjusting --- DESCRIPTION | 1 + NAMESPACE | 10 ++++++++-- NEWS.md | 6 +++++- R/ds2dd_detailed.R | 28 ++++------------------------ R/sysdata.rda | Bin 293 -> 294 bytes data-raw/metadata_names.R | 12 ++++++------ man/ds2dd_detailed.Rd | 4 ++-- 7 files changed, 26 insertions(+), 35 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index da7b1b8..eebce3a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -71,6 +71,7 @@ Collate: 'ds2dd_detailed.R' 'easy_redcap.R' 'export_redcap_instrument.R' + 'fct_drop.R' 'html_styling.R' 'mtcars_redcap.R' 'read_redcap_instrument.R' diff --git a/NAMESPACE b/NAMESPACE index b8d6fe5..3ce221b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,17 +1,21 @@ # Generated by roxygen2: do not edit by hand S3method(as_factor,character) +S3method(as_factor,data.frame) S3method(as_factor,factor) S3method(as_factor,haven_labelled) S3method(as_factor,labelled) S3method(as_factor,logical) S3method(as_factor,numeric) +S3method(as_factor,redcapcast_labelled) S3method(process_user_input,character) S3method(process_user_input,data.frame) S3method(process_user_input,default) S3method(process_user_input,response) export(REDCap_split) export(all_na) +export(apply_factor_labels) +export(apply_field_label) export(as_factor) export(case_match_regex_list) export(cast_data_overview) @@ -30,6 +34,8 @@ export(ds2dd_detailed) 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_subheader) @@ -39,6 +45,7 @@ export(guess_time_only) export(guess_time_only_filter) export(haven_all_levels) export(html_tag_wrap) +export(is.labelled) export(is_repeated_longitudinal) export(match_fields_to_form) export(named_levels) @@ -49,9 +56,7 @@ export(possibly_roman) export(process_user_input) export(read_input) export(read_redcap_instrument) -export(read_redcap_labelled) export(read_redcap_tables) -export(redcap_meta_default) export(redcap_wider) export(sanitize_split) export(set_attr) @@ -64,6 +69,7 @@ importFrom(REDCapR,redcap_event_instruments) importFrom(REDCapR,redcap_metadata_read) importFrom(REDCapR,redcap_read) importFrom(forcats,as_factor) +importFrom(forcats,fct_drop) importFrom(keyring,key_get) importFrom(keyring,key_list) importFrom(keyring,key_set) diff --git a/NEWS.md b/NEWS.md index 53d392f..fb0d4f3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,7 +2,11 @@ The hosting on shinyapps.io has given a lot of trouble recently. Modyfied package structure a little around the `shiny_cast()`, to accommodate an alternative hosting approach with all package functions included in a script instead of requiring the package. -* read_readcap_labelled(): +* NEW: A new option to `raw_or_label` in `read_readcap_tables()` has been added: "both". Get raw values with REDCap labels applied as labels. Use `as_factor()` to format factors with original labels and use the `gtsummary` package to easily get beautiful tables with original labels from REDCap. Use `fct_drop()` to drop empty levels. + +* NEW: fct_drop() has been added with an extension to `forcats::fct_drop()`, that works across data.frames. Use as `fct_drop()`. + +* CHANGE: the default data export method of `easy_redcap()` has been changed to use the new labelled data export with `read_readcap_tables()`. # REDCapCAST 24.11.3 diff --git a/R/ds2dd_detailed.R b/R/ds2dd_detailed.R index 0352ceb..ff137cc 100644 --- a/R/ds2dd_detailed.R +++ b/R/ds2dd_detailed.R @@ -99,26 +99,6 @@ hms2character <- function(data) { } -#' Default column names of a REDCap data dictionary -#' -#' @param ... ignored for now -#' -#' @return character vector -#' @export -#' -#' @examples -#' dput(redcap_meta_default()) -redcap_meta_default <- function(...) { - c( - "field_name", "form_name", "section_header", "field_type", - "field_label", "select_choices_or_calculations", "field_note", - "text_validation_type_or_show_slider_number", "text_validation_min", - "text_validation_max", "identifier", "branching_logic", "required_field", - "custom_alignment", "question_number", "matrix_group_name", "matrix_ranking", - "field_annotation" - ) -} - #' (DEPRECATED) Data set to data dictionary function #' #' @description @@ -141,7 +121,7 @@ redcap_meta_default <- function(...) { #' @param include.column.names Flag to give detailed output including new #' column names for original data set for upload. #' @param metadata Metadata column names. Default is the included -#' REDCapCAST::redcap_meta_default. +#' names(REDCapCAST::redcapcast_meta). #' #' @return data.frame or list of data.frame and vector #' @export @@ -157,7 +137,7 @@ ds2dd <- field.type = "text", field.label = NULL, include.column.names = FALSE, - metadata = REDCapCAST::redcap_meta_default() + metadata = names(REDCapCAST::redcapcast_meta) ) { dd <- data.frame(matrix(ncol = length(metadata), nrow = ncol(ds))) colnames(dd) <- metadata @@ -244,7 +224,7 @@ ds2dd <- #' or attribute `factor.labels.attr` for haven_labelled data set (imported .dta #' file with `haven::read_dta()`). #' @param metadata redcap metadata headings. Default is -#' REDCapCAST::redcap_meta_default(). +#' names(REDCapCAST::redcapcast_meta). #' @param convert.logicals convert logicals to factor. Default is TRUE. #' #' @return list of length 2 @@ -286,7 +266,7 @@ ds2dd_detailed <- function(data, field.label = NULL, field.label.attr = "label", field.validation = NULL, - metadata = REDCapCAST::redcap_meta_default(), + metadata = names(REDCapCAST::redcapcast_meta), convert.logicals = TRUE) { if (convert.logicals) { diff --git a/R/sysdata.rda b/R/sysdata.rda index c36713fd4db3438741709c8a9aaab281972acbab..bf6fdafdce1c377e33156bd2d81a5415c7eb7f9d 100644 GIT binary patch delta 280 zcmV+z0q6du0;U2ELRx4!F+o`-Q(1MCM6;0&8Grbz4GE%ZZ&dI|00006q8_7713+j1 z006|Ns(4iN)6~@To{5HnY3hEc#ArMKIiqR=v`GeBDIEMb(Z!y*bh6dn8gKU`1_XqX z42c1dBy!-u5Zt|EmUO#YVXd!V)sJf)Sm8T7!WMz>qmPr`08BKZjIK8!(y>!*A~_() z34cHXIM~A{m|;H=1nAM`uL!pKj8vyhC4W4FNIJ?QSpk58+j*w| delta 278 zcmV+x0qOpx0;K{DLRx4!F+o`-Q(4%&jR%nq8Grh!hJ+(VrpBbu8fY2~83r`aXaSQz zWND#^qXs2C8bF!?eyNeBLrpzLq%_`O9_ZeH_<}*FrcvKV67^@#+pU+b)5B)cKwwBI zp@t$51Teh-AeesJ&(z|na;2yfDtoc7-E~aTbG#2F74UmZ3qw*7rY96S=L*)qM?@I` zNq>No)Wj1iEswW?W8~v&f;DtV6s3;xuN`AHQXnP4%2hAYacx>}a&~VSS0}B6qmq45 zo^L@jYIlvuh5^_P)1j__K{&>uCWUy77Je7NhNC_;!gdEvn+@5#S%j<5?v=wq;w1=G c1ck%+JcSv{OIWz;AAjQRNT&)C8yAtF;BA6?y8r+H diff --git a/data-raw/metadata_names.R b/data-raw/metadata_names.R index 3310f14..bb83e19 100644 --- a/data-raw/metadata_names.R +++ b/data-raw/metadata_names.R @@ -7,9 +7,9 @@ # "matrix_ranking", "field_annotation" # ) -# metadata_names <- REDCapR::redcap_metadata_read( -# redcap_uri = keyring::key_get("DB_URI"), -# token = keyring::key_get("cast_api") -# )$data |> names() -# -# usethis::use_data(metadata_names, overwrite = TRUE, internal = TRUE) +metadata_names <- REDCapR::redcap_metadata_read( + redcap_uri = keyring::key_get("DB_URI"), + token = keyring::key_get("cast_api") +)$data |> names() + +usethis::use_data(metadata_names, overwrite = TRUE, internal = TRUE) diff --git a/man/ds2dd_detailed.Rd b/man/ds2dd_detailed.Rd index ded7be6..a4ec67c 100644 --- a/man/ds2dd_detailed.Rd +++ b/man/ds2dd_detailed.Rd @@ -15,7 +15,7 @@ ds2dd_detailed( field.label = NULL, field.label.attr = "label", field.validation = NULL, - metadata = REDCapCAST::redcap_meta_default(), + metadata = names(REDCapCAST::redcapcast_meta), convert.logicals = TRUE ) } @@ -55,7 +55,7 @@ or attribute `factor.labels.attr` for haven_labelled data set (imported .dta file with `haven::read_dta()`).} \item{metadata}{redcap metadata headings. Default is -REDCapCAST::redcap_meta_default().} +names(REDCapCAST::redcapcast_meta).} \item{convert.logicals}{convert logicals to factor. Default is TRUE.} }