Compare commits

..

No commits in common. "a0730cb41c68f1d41d1fe0ff82b5e6de14fcd66a" and "767d03f45ffded437b558a24485dd3fa086ea809" have entirely different histories.

18 changed files with 123 additions and 124 deletions

View File

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

View File

@ -1,11 +1,8 @@
options( options(
renv.settings.snapshot.type = "explicit", renv.settings.snapshot.type = "explicit",
renv.config.auto.snapshot = TRUE, 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") source("renv/activate.R")
if (interactive()) { if (interactive()) {

View File

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

View File

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

View File

@ -12,9 +12,7 @@
* 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: `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. 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: `read_redcap_instrument()` convenience function to retrieve complete instrument. Goes a little against the focused approach. DETAILED INSTRUCTION IS PENDING.
* 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 ### Other

View File

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

View File

@ -16,27 +16,25 @@ 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 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 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. 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.
## Use and immprovements ## Use and immprovements
Here is just a short description of the main functions: 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:
* `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. * `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. Default output is a list of data frames with one data frame for each REDCap instrument. * `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.
* `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/). * `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/).
* `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. * `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 ## Future
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. 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.
## Installation ## Installation

View File

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

View File

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

Binary file not shown.

64
inst/WORDLIST Normal file
View File

@ -0,0 +1,64 @@
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

View File

@ -1,23 +0,0 @@
% 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
}

View File

@ -1,32 +0,0 @@
% 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}

3
tests/spelling.R Normal file
View File

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

25
tests/spelling.Rout.save Normal file
View File

@ -0,0 +1,25 @@
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-creation" title: "Database casting"
output: rmarkdown::html_vignette output: rmarkdown::html_vignette
vignette: > vignette: >
%\VignetteIndexEntry{Database-creation} %\VignetteIndexEntry{Database casting}
%\VignetteEngine{knitr::rmarkdown} %\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8} %\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. 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 eval=FALSE} ```{r}
mtcars |> mtcars |>
dplyr::mutate(record_id = seq_len(dplyr::n())) |> dplyr::mutate(record_id = seq_len(dplyr::n())) |>
ds2dd() |> str() ds2dd()
``` ```
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 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. The dataset should be correctly formatted for the data dictionary to preserve as much information as possible.
```{r eval=FALSE} ```{r}
dd_ls <- mtcars |> dd_ls <- mtcars |>
dplyr::mutate(record_id = seq_len(dplyr::n())) |> dplyr::mutate(record_id = seq_len(dplyr::n())) |>
dplyr::select(record_id, dplyr::everything()) |> dplyr::select(record_id, dplyr::everything()) |>

View File

@ -1,8 +1,8 @@
--- ---
title: "Shiny-app" title: "Introduction"
output: rmarkdown::html_vignette output: rmarkdown::html_vignette
vignette: > vignette: >
%\VignetteIndexEntry{Shiny-app} %\VignetteIndexEntry{Introduction}
%\VignetteEngine{knitr::rmarkdown} %\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8} %\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: 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 eval=FALSE} ```{r}
require(REDCapCAST) require(REDCapCAST)
shiny_cast() shiny_cast()
``` ```