mirror of
https://github.com/agdamsbo/REDCapCAST.git
synced 2024-11-22 05:20:23 +01:00
including data and sorting vignette. still work to be done.
This commit is contained in:
parent
349ff695e1
commit
09690777a8
@ -49,5 +49,7 @@ Collate:
|
||||
'REDCap_split.r'
|
||||
'read_redcap_tables.R'
|
||||
'redcap_wider.R'
|
||||
'redcapcast_data.R'
|
||||
'redcapcast_meta.R'
|
||||
Language: en-US
|
||||
VignetteBuilder: knitr
|
||||
|
35
R/redcapcast_data.R
Normal file
35
R/redcapcast_data.R
Normal file
@ -0,0 +1,35 @@
|
||||
#' Data set for demonstration
|
||||
#'
|
||||
#' This is a small dataset from a REDCap database for demonstrational purposes.
|
||||
#' Contains only synthetic data.
|
||||
#'
|
||||
#' @format A data frame with 22 variables:
|
||||
#' \describe{
|
||||
#' \item{record_id}{ID, numeric}
|
||||
#' \item{redcap_event_name}{Event name, character}
|
||||
#' \item{redcap_repeat_instrument}{Repeat instrument, character}
|
||||
#' \item{redcap_repeat_instance}{Repeat instance, numeric}
|
||||
#' \item{cpr}{CPR number, character}
|
||||
#' \item{inclusion}{Inclusion date, date}
|
||||
#' \item{dob}{Date of birth, date}
|
||||
#' \item{age}{Age decimal, numeric}
|
||||
#' \item{age_integer}{Age integer, numeric}
|
||||
#' \item{sex}{Legal sex, character}
|
||||
#' \item{cohabitation}{Cohabitation status, character}
|
||||
#' \item{hypertension}{Hypertension, character}
|
||||
#' \item{diabetes}{diabetes, character}
|
||||
#' \item{region}{region, character}
|
||||
#' \item{base_complete}{Completed, character}
|
||||
#' \item{mrs_assessed}{mRS Assessed, character}
|
||||
#' \item{mrs_date}{Assesment date, date}
|
||||
#' \item{mrs_score}{Score, numeric}
|
||||
#' \item{mrs_complete}{Complete, numeric}
|
||||
#' \item{event_date}{Event date, date}
|
||||
#' \item{event_type}{Event type, character}
|
||||
#' \item{event_complete}{Completed, character}
|
||||
#'
|
||||
#' }
|
||||
#' @usage data(redcapcast_data)
|
||||
"redcapcast_data"
|
||||
|
||||
|
29
R/redcapcast_meta.R
Normal file
29
R/redcapcast_meta.R
Normal file
@ -0,0 +1,29 @@
|
||||
#' REDCap matedata from data base
|
||||
#'
|
||||
#' This metadata dataset from a REDCap database is for demonstrational purposes.
|
||||
#'
|
||||
#' @format A data frame with 22 variables:
|
||||
#' \describe{
|
||||
#' \item{field_name}{field_name, character}
|
||||
#' \item{form_name}{form_name, character}
|
||||
#' \item{section_header}{section_header, character}
|
||||
#' \item{field_type}{field_type, character}
|
||||
#' \item{field_label}{field_label, character}
|
||||
#' \item{select_choices_or_calculations}{select_choices_or_calculations, character}
|
||||
#' \item{field_note}{field_note, character}
|
||||
#' \item{text_validation_type_or_show_slider_number}{text_validation_type_or_show_slider_number, character}
|
||||
#' \item{text_validation_min}{text_validation_min, character}
|
||||
#' \item{text_validation_max}{text_validation_max, character}
|
||||
#' \item{identifier}{identifier, character}
|
||||
#' \item{branching_logic}{branching_logic, character}
|
||||
#' \item{required_field}{required_field, character}
|
||||
#' \item{custom_alignment}{custom_alignment, character}
|
||||
#' \item{question_number}{question_number, character}
|
||||
#' \item{matrix_group_name}{matrix_group_name, character}
|
||||
#' \item{matrix_ranking}{matrix_ranking, character}
|
||||
#' \item{field_annotation}{field_annotation, character}
|
||||
#' }
|
||||
#' @usage data(redcapcast_meta)
|
||||
"redcapcast_meta"
|
||||
|
||||
|
8
data-raw/redcapcast_data.R
Normal file
8
data-raw/redcapcast_data.R
Normal file
@ -0,0 +1,8 @@
|
||||
## code to prepare `redcapcast_data` dataset goes here
|
||||
|
||||
redcapcast_data <- REDCapR::redcap_read(redcap_uri = uri,
|
||||
token = keyring::key_get("cast_api"),
|
||||
raw_or_label = "label"
|
||||
)$data
|
||||
|
||||
usethis::use_data(redcapcast_data, overwrite = TRUE)
|
6
data-raw/redcapcast_meta.R
Normal file
6
data-raw/redcapcast_meta.R
Normal file
@ -0,0 +1,6 @@
|
||||
## code to prepare `redcapcast_meta` dataset goes here
|
||||
redcapcast_meta <- REDCapR::redcap_metadata_read(redcap_uri = uri,
|
||||
token = keyring::key_get("cast_api")
|
||||
)$data
|
||||
|
||||
usethis::use_data(redcapcast_meta, overwrite = TRUE)
|
BIN
data/redcapcast_data.rda
Normal file
BIN
data/redcapcast_data.rda
Normal file
Binary file not shown.
BIN
data/redcapcast_meta.rda
Normal file
BIN
data/redcapcast_meta.rda
Normal file
Binary file not shown.
@ -3,5 +3,5 @@ pkgdown: 2.0.7
|
||||
pkgdown_sha: ~
|
||||
articles:
|
||||
Introduction: Introduction.html
|
||||
last_built: 2023-04-13T08:56Z
|
||||
last_built: 2023-04-13T10:14Z
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
@ -39,6 +39,12 @@
|
||||
<url>
|
||||
<loc>/reference/redcap_wider.html</loc>
|
||||
</url>
|
||||
<url>
|
||||
<loc>/reference/redcapcast_data.html</loc>
|
||||
</url>
|
||||
<url>
|
||||
<loc>/reference/redcapcast_meta.html</loc>
|
||||
</url>
|
||||
<url>
|
||||
<loc>/reference/sanitize_split.html</loc>
|
||||
</url>
|
||||
|
42
man/redcapcast_data.Rd
Normal file
42
man/redcapcast_data.Rd
Normal file
@ -0,0 +1,42 @@
|
||||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/redcapcast_data.R
|
||||
\docType{data}
|
||||
\name{redcapcast_data}
|
||||
\alias{redcapcast_data}
|
||||
\title{Data set for demonstration}
|
||||
\format{
|
||||
A data frame with 22 variables:
|
||||
\describe{
|
||||
\item{record_id}{ID, numeric}
|
||||
\item{redcap_event_name}{Event name, character}
|
||||
\item{redcap_repeat_instrument}{Repeat instrument, character}
|
||||
\item{redcap_repeat_instance}{Repeat instance, numeric}
|
||||
\item{cpr}{CPR number, character}
|
||||
\item{inclusion}{Inclusion date, date}
|
||||
\item{dob}{Date of birth, date}
|
||||
\item{age}{Age decimal, numeric}
|
||||
\item{age_integer}{Age integer, numeric}
|
||||
\item{sex}{Legal sex, character}
|
||||
\item{cohabitation}{Cohabitation status, character}
|
||||
\item{hypertension}{Hypertension, character}
|
||||
\item{diabetes}{diabetes, character}
|
||||
\item{region}{region, character}
|
||||
\item{base_complete}{Completed, character}
|
||||
\item{mrs_assessed}{mRS Assessed, character}
|
||||
\item{mrs_date}{Assesment date, date}
|
||||
\item{mrs_score}{Score, numeric}
|
||||
\item{mrs_complete}{Complete, numeric}
|
||||
\item{event_date}{Event date, date}
|
||||
\item{event_type}{Event type, character}
|
||||
\item{event_complete}{Completed, character}
|
||||
|
||||
}
|
||||
}
|
||||
\usage{
|
||||
data(redcapcast_data)
|
||||
}
|
||||
\description{
|
||||
This is a small dataset from a REDCap database for demonstrational purposes.
|
||||
Contains only synthetic data.
|
||||
}
|
||||
\keyword{datasets}
|
36
man/redcapcast_meta.Rd
Normal file
36
man/redcapcast_meta.Rd
Normal file
@ -0,0 +1,36 @@
|
||||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/redcapcast_meta.R
|
||||
\docType{data}
|
||||
\name{redcapcast_meta}
|
||||
\alias{redcapcast_meta}
|
||||
\title{REDCap matedata from data base}
|
||||
\format{
|
||||
A data frame with 22 variables:
|
||||
\describe{
|
||||
\item{field_name}{field_name, character}
|
||||
\item{form_name}{form_name, character}
|
||||
\item{section_header}{section_header, character}
|
||||
\item{field_type}{field_type, character}
|
||||
\item{field_label}{field_label, character}
|
||||
\item{select_choices_or_calculations}{select_choices_or_calculations, character}
|
||||
\item{field_note}{field_note, character}
|
||||
\item{text_validation_type_or_show_slider_number}{text_validation_type_or_show_slider_number, character}
|
||||
\item{text_validation_min}{text_validation_min, character}
|
||||
\item{text_validation_max}{text_validation_max, character}
|
||||
\item{identifier}{identifier, character}
|
||||
\item{branching_logic}{branching_logic, character}
|
||||
\item{required_field}{required_field, character}
|
||||
\item{custom_alignment}{custom_alignment, character}
|
||||
\item{question_number}{question_number, character}
|
||||
\item{matrix_group_name}{matrix_group_name, character}
|
||||
\item{matrix_ranking}{matrix_ranking, character}
|
||||
\item{field_annotation}{field_annotation, character}
|
||||
}
|
||||
}
|
||||
\usage{
|
||||
data(redcapcast_meta)
|
||||
}
|
||||
\description{
|
||||
This metadata dataset from a REDCap database is for demonstrational purposes.
|
||||
}
|
||||
\keyword{datasets}
|
@ -20,57 +20,49 @@ library(REDCapCAST)
|
||||
|
||||
This vignette covers the included functions and basic functionality.
|
||||
|
||||
A dataset and a meta data file are provided with the package for demonstration of the functions.
|
||||
|
||||
## Splitting the dataset
|
||||
|
||||
```{r eval=FALSE}
|
||||
keyring::key_set("handbook_api")
|
||||
keyring::key_set("cast_api")
|
||||
```
|
||||
|
||||
```{r include=FALSE}
|
||||
uri <- keyring::key_get("DB_URI")
|
||||
```
|
||||
|
||||
|
||||
```{r}
|
||||
dataset <- REDCapR::redcap_read_oneshot(redcap_uri = uri,
|
||||
token = keyring::key_get("cast_api"))$data
|
||||
|
||||
dataset |> gt::gt()
|
||||
redcapcast_data |> gt::gt()
|
||||
```
|
||||
|
||||
```{r}
|
||||
metadata <- REDCapR::redcap_metadata_read(redcap_uri = uri,
|
||||
token = keyring::key_get("cast_api"))$data
|
||||
metadata |> gt::gt()
|
||||
redcapcast_meta |> gt::gt()
|
||||
```
|
||||
```{r}
|
||||
list <-
|
||||
REDCapCAST::REDCap_split(records = dataset,
|
||||
metadata = metadata,
|
||||
REDCapCAST::REDCap_split(records = redcapcast_data,
|
||||
metadata = redcapcast_meta,
|
||||
forms = "repeating")
|
||||
str(list)
|
||||
```
|
||||
|
||||
```{r}
|
||||
list <-
|
||||
REDCapCAST::REDCap_split(records = dataset,
|
||||
metadata = metadata,
|
||||
REDCapCAST::REDCap_split(records = redcapcast_data,
|
||||
metadata = redcapcast_meta,
|
||||
forms = "all")
|
||||
str(list)
|
||||
```
|
||||
|
||||
## Reading data from REDCap
|
||||
|
||||
```{r}
|
||||
ds <- read_redcap_tables(uri = uri, token = keyring::key_get("cast_api"))
|
||||
str(ds)
|
||||
This function wraps all the above demonstrated function to get the dataset, the metadata, apply the `REDCap_split`function and then a bit of cleaning.
|
||||
|
||||
The function works verysimilarly as the `REDCapR::redcap_read()`.
|
||||
|
||||
```{r eval=FALSE}
|
||||
# read_redcap_tables(uri = "YOUR URI", token = "YOUR TOKEN")
|
||||
|
||||
# ds <- read_redcap_tables(uri = key_get("DB_URI"), token = key_get("cast_api"))
|
||||
```
|
||||
|
||||
## Pivotting to wider format
|
||||
|
||||
```{r}
|
||||
redcap_wider(ds) |> gt::gt()
|
||||
# redcap_wider(ds)
|
||||
```
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user