Transform a supertibble into an XLSX file, with each REDCap data tibble in a separate sheet.
Usage
write_redcap_xlsx(
supertbl,
file,
add_labelled_column_headers = NULL,
use_labels_for_sheet_names = TRUE,
include_toc_sheet = TRUE,
include_metadata_sheet = TRUE,
table_style = "tableStyleLight8",
column_width = "auto",
recode_logical = TRUE,
na_replace = "",
overwrite = FALSE
)Arguments
- supertbl
A supertibble generated using
read_redcap().- file
The name of the file to which the output will be written.
- add_labelled_column_headers
If
TRUE, the first row of each sheet will contain variable labels, with variable names in the second row. IfFALSE, variable names will be in the first row. The default value,NULL, tries to determine ifsupertblcontains variable labels and, if present, includes them in the first row. Thelabelledpackage must be installed ifadd_labelled_column_headersisTRUE.- use_labels_for_sheet_names
If
FALSE, sheet names will come from the REDCap instrument names. IfTRUE, sheet names will come from instrument labels. The default isTRUE.- include_toc_sheet
If
TRUE, the first sheet in the XLSX output will be a table of contents, providing information about each data tibble in the workbook. The default isTRUE.- include_metadata_sheet
If
TRUE, the final sheet in the XLSX output will contain metadata about each variable, combining the content ofsupertbl$redcap_metadata. The default isTRUE.- table_style
Any Excel table style name or "none". For more details, see the "formatting" vignette of the
openxlsxpackage. The default is "tableStyleLight8".- column_width
Sets the width of columns throughout the workbook. The default is "auto", but you can specify a numeric value.
- recode_logical
If
TRUE, fields with "yesno" field type are recoded to "yes"/"no" and fields with a "checkbox" field type are recoded to "Checked"/"Unchecked". The default isTRUE.- na_replace
The value used to replace
NAvalues insupertbl. The default is "".- overwrite
If
FALSE, will not overwritefilewhen it exists. The default isFALSE.
Examples
if (FALSE) { # \dontrun{
redcap_uri <- Sys.getenv("REDCAP_URI")
token <- Sys.getenv("REDCAP_TOKEN")
supertbl <- read_redcap(redcap_uri, token)
supertbl %>%
write_redcap_xlsx(file = "supertibble.xlsx")
# Add variable labels
library(labelled)
supertbl %>%
make_labelled() %>%
write_redcap_xlsx(file = "supertibble.xlsx", add_labelled_column_headers = TRUE)
} # }
