Compare commits

..

5 Commits

18 changed files with 124 additions and 123 deletions

View File

@ -16,3 +16,4 @@
^cran-comments\.md$
^CRAN-SUBMISSION$
drafting
app

View File

@ -1,8 +1,11 @@
options(
renv.settings.snapshot.type = "explicit",
renv.config.auto.snapshot = TRUE,
renv.config.pak.enabled = TRUE
renv.config.pak.enabled = TRUE,
rmarkdown.html_vignette.check_title = FALSE
)
source("renv/activate.R")
if (interactive()) {

View File

@ -8,21 +8,19 @@ Authors@R: c(
comment = c(ORCID = "0000-0001-6948-9498")))
Description: Originally forked from the R part of 'REDCapRITS' by Paul Egeler.
See <https://github.com/pegeler/REDCapRITS>.
Handles castellated datasets from 'REDCap' projects with repeating instruments.
Assists in casting tidy tables from raw 'REDCap' data exports for each
repeated instrument. Keeps a focused data export approach, by allowing to
only export required data from the database.
'REDCap' database casting and handling of castellated data when using
repeated instruments and longitudinal projects. Keeps a focused data export
approach, by allowing to only export required data from the database.
'REDCap' (Research Electronic Data Capture) is a secure, web-based software
platform designed to support data capture for research studies, providing
1) an intuitive interface for validated data capture; 2) audit trails for
tracking data manipulation and export procedures; 3) automated export
procedures for seamless data downloads to common statistical packages; and
4) procedures for data integration and interoperability with external sources
(Harris et al (2009) <doi:10.1016/j.jbi.2008.08.010>;
4) procedures for data integration and interoperability with external
sources (Harris et al (2009) <doi:10.1016/j.jbi.2008.08.010>;
Harris et al (2019) <doi:10.1016/j.jbi.2019.103208>).
Depends: R (>= 3.4.0)
Suggests:
spelling,
httr,
jsonlite,
testthat,
@ -38,7 +36,9 @@ Suggests:
devtools,
roxygen2,
openxlsx2,
rsconnect
rsconnect,
shiny,
spelling
License: GPL (>= 3)
Encoding: UTF-8
LazyData: true
@ -61,6 +61,7 @@ Collate:
'ds2dd.R'
'ds2dd_detailed.R'
'easy_redcap.R'
'mtcars_redcap.R'
'read_redcap_instrument.R'
'read_redcap_tables.R'
'redcap_wider.R'

View File

@ -3,6 +3,7 @@
export(REDCap_split)
export(clean_redcap_name)
export(d2w)
export(deploy_shiny)
export(ds2dd)
export(ds2dd_detailed)
export(easy_redcap)

View File

@ -12,7 +12,9 @@
* NEW: `ds2dd_detailed()`: extension of the `ds2dd()`, which serves to preserve as much metadata as possible automatically. Depends on a group of helper functions also introduced. Of special note is the `guess_time_only_filter()`, which will try to guess which columns/variables should be formatted as time only formats. Supports hms time format. DETAILED INSTRUCTION AND VIGNETTE IS PENDING.
* NEW: `read_redcap_instrument()` convenience function to retrieve complete instrument. Goes a little against the focused approach. DETAILED INSTRUCTION IS PENDING.
* NEW: `read_redcap_instrument()`: convenience function to retrieve complete instrument. Goes a little against the focused approach. With `REDCapR::redcap_read()` you can specify a form to download. You have to also specify the record id variable though. This is done for you with `read_redcap_instrument()`. Nothing fancy.
* NEW: `shiny_cast()`: [Shiny](https://www.rstudio.com/products/shiny/) application to ease the process of converting a spreadsheet/data set to a REDCap database. The app runs locally and data is transferred securely. You can just create and upload the data dictionary, but you can also transfer the given data in the same process. I plan to host the app with shinyapps.io, but for now you can run it locally.
### Other

23
R/mtcars_redcap.R Normal file
View File

@ -0,0 +1,23 @@
#' mtcars dataset slightly modified to use for Shiny app upload demonstration
#'
#'
#' @format A data frame with 13 variables:
#' \describe{
#' \item{record_id}{ID, numeric}
#' \item{mpg}{ID, numeric}
#' \item{cyl}{ID, numeric}
#' \item{disp}{ID, numeric}
#' \item{hp}{ID, numeric}
#' \item{drat}{ID, numeric}
#' \item{wt}{ID, numeric}
#' \item{qsec}{ID, numeric}
#' \item{vs}{ID, numeric}
#' \item{am}{ID, numeric}
#' \item{gear}{ID, numeric}
#' \item{carb}{ID, numeric}
#' \item{name}{original rownames, charater}
#'
#' }
#' @usage data(mtcars_redcap)
"mtcars_redcap"

View File

@ -1,3 +1,4 @@
utils::globalVariables(c("server"))
#' Shiny server factory
#'
#' @return shiny server
@ -36,6 +37,9 @@ shiny_cast <- function() {
#' Deploy the Shiny app with rsconnect
#'
#' @param path app folder path
#' @param name.app name of deployed app
#'
#' @return deploy
#' @export
#'
@ -43,9 +47,6 @@ shiny_cast <- function() {
#' # deploy_shiny
#'
deploy_shiny <- function(path=here::here("app/"), name.app="shiny_cast"){
# Ensure to install latest package version
renv::install("agdamsbo/REDCapCAST")
# Connecting
rsconnect::setAccountInfo(
name = "cognitiveindex",

View File

@ -16,25 +16,27 @@ REDCap database casting and handling of castellated data when using repeated ins
This package is a fork of [pegeler/REDCapRITS](https://github.com/pegeler/REDCapRITS). The REDCapRITS represents great and extensive work to handle castellated REDCap data in different programming languages. This fork is purely minded on R usage and includes a few implementations of the main `REDCap_split` function.
THis package is very much to be seen as an attempt at a REDCap-R foundry for handling both the transition from dataset/variable list to database and the other way, from REDCap database to a tidy dataset. The goal was also to allow for a "minimal data" approach by allowing to filter records, instruments and variables in the export to only download data needed. I think this approach is desireable for handling sensitive, clinical data. No similar functionality is available from similar tools (like `REDCapR` or `REDCapTidieR`). Please refer to [REDCap-Tools](https://redcap-tools.github.io/) for other great tools.
This package is very much to be seen as an attempt at a R-to-REDCap-to-R foundry for handling both the transition from dataset/variable list to database and the other way, from REDCap database to a tidy dataset. The goal was also to allow for a "minimal data" approach by allowing to filter records, instruments and variables in the export to only download data needed. I think this approach is desirable for handling sensitive, clinical data. Please refer to [REDCap-Tools](https://redcap-tools.github.io/) for other great tools for working with REDCap in R.
## Use and immprovements
This package is primarily relevant for working with longitudinal projects and/or projects using repeated instruments. Here is just a short descirption of the main functions:
Here is just a short description of the main functions:
* `REDcap_split()`: Works largely as the original `REDCapRITS::REDCap_split()`. It takes a REDCap dataset and metadata (data dictionary) to split the data set into a list of dataframes of instruments.
* `read_redcap_tables()`: wraps the use of [`REDCapR::redcap_read()`](https://github.com/OuhscBbmc/REDCapR) with `REDCap_split()` to ease the export of REDCap data.
* `read_redcap_tables()`: wraps the use of [`REDCapR::redcap_read()`](https://github.com/OuhscBbmc/REDCapR) with `REDCap_split()` to ease the export of REDCap data. Default output is a list of data frames with one data frame for each REDCap instrument.
* `redcap_wider()`: pivots each data frame with repeated instruments to a wide format utilizing the [`tidyr::pivot_wider()`](https://tidyr.tidyverse.org/reference/pivot_wider.html) from the [tidyverse](https://www.tidyverse.org/).
* `redcap_wider()`: joins and pivots a list of data frames with repeated instruments to a wide format utilizing the [`tidyr::pivot_wider()`](https://tidyr.tidyverse.org/reference/pivot_wider.html) from the [tidyverse](https://www.tidyverse.org/).
* `easy_redcap()`: combines secure API key storage with the `keyring`-package, focused data retrieval and optional widening. This is the recommended approach for easy data access and analysis.
...
* `ds2dd_detailed()`: Converts a data set to a data dictionary for upload to a new REDCap database. Variables (fields) and instruments in a REDCap data base are defined by this data dictionary.
* `shiny_cast()`: [Shiny](https://www.rstudio.com/products/shiny/) application to ease the process of converting a spreadsheet/data set to a REDCap database. The app runs locally and data is transferred securely. You can just create and upload the data dictionary, but you can also transfer the given data in the same process.
## Future
The plan with this package is to be bundled with a Handbook on working with REDCap from R. I plan to also include functionality to assist in casting (yes, pun intended) the initial REDCap database.
The plan with this package is to be bundled with a Handbook on working with REDCap from R. This work is in progress but is limited by the time available. Please feel free to contact me or create and issue with ideas for future additions.
## Installation

View File

@ -40,12 +40,12 @@ ui <- shiny::fluidPage(
shiny::textInput(
inputId = "uri",
label = "URI",
value = "https://redcap.au.dk/api/"
value = "https://redcap.your.institution/api/"
),
shiny::textInput(
inputId = "api",
label = "API key",
value = "21CF2C17EA1CA4F3688DF991C8FE3EBF"
value = ""
),
shiny::actionButton(
inputId = "upload.meta",

View File

@ -1,5 +1,9 @@
mtcars |> dplyr::mutate(record_id=seq_len(n()),
mtcars_redcap <- mtcars |> dplyr::mutate(record_id=seq_len(dplyr::n()),
name=rownames(mtcars)
) |>
dplyr::select(record_id,dplyr::everything()) |>
dplyr::select(record_id,dplyr::everything())
mtcars_redcap |>
write.csv(here::here("data/mtcars_redcap.csv"),row.names = FALSE)
usethis::use_data(mtcars_redcap, overwrite = TRUE)

BIN
data/mtcars_redcap.rda Normal file

Binary file not shown.

View File

@ -1,64 +0,0 @@
Assesment
CMD
Codecov
DOI
DataDictionary
Dependens
GStat
GithubActions
JSON
Lifecycle
METACRAN
POSIXct
Pivotting
README
REDCap
REDCapR
REDCapRITS
Whishes
al
api
attr
da
dafault
datetime
demonstrational
descirption
desireable
dmy
doi
dplyr
ds
dta
et
gues
hms
ical
ics
immprovements
jbi
keyring
labelled
labelling
mRS
matadata
md
mdy
natively
ncol
og
param
pegeler
perl
pos
readr
sel
stRoke
stata
strsplit
thorugh
tibble
tidyverse
uri
wil
ymd

23
man/deploy_shiny.Rd Normal file
View File

@ -0,0 +1,23 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/shiny_cast.R
\name{deploy_shiny}
\alias{deploy_shiny}
\title{Deploy the Shiny app with rsconnect}
\usage{
deploy_shiny(path = here::here("app/"), name.app = "shiny_cast")
}
\arguments{
\item{path}{app folder path}
\item{name.app}{name of deployed app}
}
\value{
deploy
}
\description{
Deploy the Shiny app with rsconnect
}
\examples{
# deploy_shiny
}

32
man/mtcars_redcap.Rd Normal file
View File

@ -0,0 +1,32 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/mtcars_redcap.R
\docType{data}
\name{mtcars_redcap}
\alias{mtcars_redcap}
\title{mtcars dataset slightly modified to use for Shiny app upload demonstration}
\format{
A data frame with 13 variables:
\describe{
\item{record_id}{ID, numeric}
\item{mpg}{ID, numeric}
\item{cyl}{ID, numeric}
\item{disp}{ID, numeric}
\item{hp}{ID, numeric}
\item{drat}{ID, numeric}
\item{wt}{ID, numeric}
\item{qsec}{ID, numeric}
\item{vs}{ID, numeric}
\item{am}{ID, numeric}
\item{gear}{ID, numeric}
\item{carb}{ID, numeric}
\item{name}{original rownames, charater}
}
}
\usage{
data(mtcars_redcap)
}
\description{
mtcars dataset slightly modified to use for Shiny app upload demonstration
}
\keyword{datasets}

View File

@ -1,3 +0,0 @@
if(requireNamespace('spelling', quietly = TRUE))
spelling::spell_check_test(vignettes = TRUE, error = FALSE,
skip_on_cran = TRUE)

View File

@ -1,25 +0,0 @@
R version 3.4.1 (2017-06-30) -- "Single Candle"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin15.6.0 (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> if(requireNamespace('spelling', quietly = TRUE))
+ spelling::spell_check_test(vignettes = TRUE, error = FALSE,
+ skip_on_cran = TRUE)
All Done!
>
> proc.time()
user system elapsed
0.372 0.039 0.408

View File

@ -1,8 +1,8 @@
---
title: "Database casting"
title: "Database-creation"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Database casting}
%\VignetteIndexEntry{Database-creation}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
@ -22,17 +22,17 @@ library(REDCapCAST)
THe first iteration of a dataset to data dictionary function is the `ds2dd()`, which creates a very basic data dictionary with all variables stored as text. This is sufficient for just storing old datasets/spreadsheets securely in REDCap.
```{r}
```{r eval=FALSE}
mtcars |>
dplyr::mutate(record_id = seq_len(dplyr::n())) |>
ds2dd()
ds2dd() |> str()
```
The more advanced `ds2dd_detailed()` is a natural development. It will try to apply the most common data classes for data validation and will assume that the first column is the id number. It outputs a list with the dataset with modified variable names to comply with REDCap naming conventions and a data dictionary.
The dataset should be correctly formatted for the data dictionary to preserve as much information as possible.
```{r}
```{r eval=FALSE}
dd_ls <- mtcars |>
dplyr::mutate(record_id = seq_len(dplyr::n())) |>
dplyr::select(record_id, dplyr::everything()) |>

View File

@ -1,8 +1,8 @@
---
title: "Introduction"
title: "Shiny-app"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Introduction}
%\VignetteIndexEntry{Shiny-app}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
@ -20,7 +20,7 @@ library(REDCapCAST)
To make the easiest possible transistion from spreadsheet/dataset to REDCap, I have created a small Shiny app, which adds a graphical interface to the casting of a data dictionary and data upload. Install the package and run the app as follows:
```{r}
```{r eval=FALSE}
require(REDCapCAST)
shiny_cast()
```