This commit is contained in:
AG Damsbo 2023-04-14 11:47:23 +02:00
parent 80f1e6fe12
commit d054f5a420
16 changed files with 353 additions and 225 deletions

View File

@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand # Generated by roxygen2: do not edit by hand
export(REDCap_split) export(REDCap_split)
export(clean_redcap_name)
export(focused_metadata) export(focused_metadata)
export(match_fields_to_form) export(match_fields_to_form)
export(read_redcap_tables) export(read_redcap_tables)

Binary file not shown.

View File

@ -1,5 +1,5 @@
## code to prepare `redcapcast_meta` dataset goes here ## code to prepare `redcapcast_meta` dataset goes here
redcapcast_meta <- REDCapR::redcap_metadata_read(redcap_uri = uri, redcapcast_meta <- REDCapR::redcap_metadata_read(redcap_uri = keyring::key_get("DB_URI"),
token = keyring::key_get("cast_api") token = keyring::key_get("cast_api")
)$data )$data

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -3,5 +3,5 @@ pkgdown: 2.0.7
pkgdown_sha: ~ pkgdown_sha: ~
articles: articles:
Introduction: Introduction.html Introduction: Introduction.html
last_built: 2023-04-14T07:46Z last_built: 2023-04-14T09:45Z

View File

@ -0,0 +1,101 @@
<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><meta name="description" content="Stepwise removal on non-alphanumeric characters, trailing white space,
substitutes spaces for underscores and converts to lower case.
Trying to make up for different naming conventions."><title>clean_redcap_name — clean_redcap_name • REDCapCAST</title><script src="../deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><link href="../deps/bootstrap-5.2.2/bootstrap.min.css" rel="stylesheet"><script src="../deps/bootstrap-5.2.2/bootstrap.bundle.min.js"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous"><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous"><!-- bootstrap-toc --><script src="https://cdn.jsdelivr.net/gh/afeld/bootstrap-toc@v1.0.1/dist/bootstrap-toc.min.js" integrity="sha256-4veVQbu7//Lk5TSmc7YV48MxtMy98e26cf5MrgZYnwo=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- search --><script src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.js" integrity="sha512-zv6Ywkjyktsohkbp9bb45V6tEMoWhzFzXis+LrMehmJZZSys19Yxf1dopHx7WzIKxr5tK2dVcYmaCk2uqdjF4A==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/autocomplete.js/0.38.0/autocomplete.jquery.min.js" integrity="sha512-GU9ayf+66Xx2TmpxqJpliWbT5PiGYxpaG8rfnBEk1LL8l1KGkRShhngwdXK1UgqhAzWpZHSiYPc09/NwDQIGyg==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js" integrity="sha512-5CYOlHXGh6QpOFA/TeTylKLWfB3ftPsde7AnmhuitiTX4K5SqCLBeKro6sPS8ilsz1Q4NRx3v8Ko2IBiszzdww==" crossorigin="anonymous"></script><!-- pkgdown --><script src="../pkgdown.js"></script><meta property="og:title" content="clean_redcap_name — clean_redcap_name"><meta property="og:description" content="Stepwise removal on non-alphanumeric characters, trailing white space,
substitutes spaces for underscores and converts to lower case.
Trying to make up for different naming conventions."><!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]--></head><body>
<a href="#main" class="visually-hidden-focusable">Skip to contents</a>
<nav class="navbar fixed-top navbar-light navbar-expand-lg bg-light"><div class="container">
<a class="navbar-brand me-2" href="../index.html">REDCapCAST</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">23.4.1</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div id="navbar" class="collapse navbar-collapse ms-3">
<ul class="navbar-nav me-auto"><li class="active nav-item">
<a class="nav-link" href="../reference/index.html">Reference</a>
</li>
<li class="nav-item dropdown">
<a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" role="button" aria-expanded="false" aria-haspopup="true" id="dropdown-articles">Articles</a>
<div class="dropdown-menu" aria-labelledby="dropdown-articles">
<a class="dropdown-item" href="../articles/Introduction.html">Introduction</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="../news/index.html">Changelog</a>
</li>
</ul><form class="form-inline my-2 my-lg-0" role="search">
<input type="search" class="form-control me-sm-2" aria-label="Toggle navigation" name="search-input" data-search-index="../search.json" id="search-input" placeholder="Search for" autocomplete="off"></form>
<ul class="navbar-nav"><li class="nav-item">
<a class="external-link nav-link" href="https://github.com/agdamsbo/REDCapCAST/" aria-label="github">
<span class="fab fa fab fa-github fa-lg"></span>
</a>
</li>
</ul></div>
</div>
</nav><div class="container template-reference-topic">
<div class="row">
<main id="main" class="col-md-9"><div class="page-header">
<img src="" class="logo" alt=""><h1>clean_redcap_name</h1>
<small class="dont-index">Source: <a href="https://github.com/agdamsbo/REDCapCAST/blob/HEAD/R/utils.r" class="external-link"><code>R/utils.r</code></a></small>
<div class="d-none name"><code>clean_redcap_name.Rd</code></div>
</div>
<div class="ref-description section level2">
<p>Stepwise removal on non-alphanumeric characters, trailing white space,
substitutes spaces for underscores and converts to lower case.
Trying to make up for different naming conventions.</p>
</div>
<div class="section level2">
<h2 id="ref-usage">Usage<a class="anchor" aria-label="anchor" href="#ref-usage"></a></h2>
<div class="sourceCode"><pre class="sourceCode r"><code><span><span class="fu">clean_redcap_name</span><span class="op">(</span><span class="va">x</span><span class="op">)</span></span></code></pre></div>
</div>
<div class="section level2">
<h2 id="arguments">Arguments<a class="anchor" aria-label="anchor" href="#arguments"></a></h2>
<dl><dt>x</dt>
<dd><p>vector or data frame for cleaning</p></dd>
</dl></div>
<div class="section level2">
<h2 id="value">Value<a class="anchor" aria-label="anchor" href="#value"></a></h2>
<p>vector or data frame, same format as input</p>
</div>
</main><aside class="col-md-3"><nav id="toc"><h2>On this page</h2>
</nav></aside></div>
<footer><div class="pkgdown-footer-left">
<p></p><p>Developed by Andreas Gammelgaard Damsbo, Paul Egeler.</p>
</div>
<div class="pkgdown-footer-right">
<p></p><p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.7.</p>
</div>
</footer></div>
</body></html>

View File

@ -67,6 +67,11 @@
<dd>Split REDCap repeating instruments table into multiple tables</dd> <dd>Split REDCap repeating instruments table into multiple tables</dd>
</dl><dl><dt> </dl><dl><dt>
<code><a href="clean_redcap_name.html">clean_redcap_name()</a></code>
</dt>
<dd>clean_redcap_name</dd>
</dl><dl><dt>
<code><a href="focused_metadata.html">focused_metadata()</a></code> <code><a href="focused_metadata.html">focused_metadata()</a></code>
</dt> </dt>
<dd>focused_metadata</dd> <dd>focused_metadata</dd>

View File

@ -107,7 +107,7 @@ Contains only synthetic data.</p>
<dt>region</dt> <dt>region</dt>
<dd><p>region, character</p></dd> <dd><p>region, character</p></dd>
<dt>base_complete</dt> <dt>baseline_data_start_complete</dt>
<dd><p>Completed, character</p></dd> <dd><p>Completed, character</p></dd>
<dt>mrs_assessed</dt> <dt>mrs_assessed</dt>
@ -128,7 +128,7 @@ Contains only synthetic data.</p>
<dt>event_type</dt> <dt>event_type</dt>
<dd><p>Event type, character</p></dd> <dd><p>Event type, character</p></dd>
<dt>event_complete</dt> <dt>new_event_complete</dt>
<dd><p>Completed, character</p></dd> <dd><p>Completed, character</p></dd>

File diff suppressed because one or more lines are too long

View File

@ -24,6 +24,9 @@
<url> <url>
<loc>/reference/REDCap_split.html</loc> <loc>/reference/REDCap_split.html</loc>
</url> </url>
<url>
<loc>/reference/clean_redcap_name.html</loc>
</url>
<url> <url>
<loc>/reference/focused_metadata.html</loc> <loc>/reference/focused_metadata.html</loc>
</url> </url>

19
man/clean_redcap_name.Rd Normal file
View File

@ -0,0 +1,19 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils.r
\name{clean_redcap_name}
\alias{clean_redcap_name}
\title{clean_redcap_name}
\usage{
clean_redcap_name(x)
}
\arguments{
\item{x}{vector or data frame for cleaning}
}
\value{
vector or data frame, same format as input
}
\description{
Stepwise removal on non-alphanumeric characters, trailing white space,
substitutes spaces for underscores and converts to lower case.
Trying to make up for different naming conventions.
}

View File

@ -21,14 +21,14 @@ A data frame with 22 variables:
\item{hypertension}{Hypertension, character} \item{hypertension}{Hypertension, character}
\item{diabetes}{diabetes, character} \item{diabetes}{diabetes, character}
\item{region}{region, character} \item{region}{region, character}
\item{base_complete}{Completed, character} \item{baseline_data_start_complete}{Completed, character}
\item{mrs_assessed}{mRS Assessed, character} \item{mrs_assessed}{mRS Assessed, character}
\item{mrs_date}{Assesment date, date} \item{mrs_date}{Assesment date, date}
\item{mrs_score}{Score, numeric} \item{mrs_score}{Score, numeric}
\item{mrs_complete}{Complete, numeric} \item{mrs_complete}{Complete, numeric}
\item{event_date}{Event date, date} \item{event_date}{Event date, date}
\item{event_type}{Event type, character} \item{event_type}{Event type, character}
\item{event_complete}{Completed, character} \item{new_event_complete}{Completed, character}
} }
} }

View File

@ -6,5 +6,7 @@
# ) # )
# } # }
# setwd("tests/testthat")
get_data_location <- function(x) get_data_location <- function(x)
file.path("data", x) file.path("data", x)

View File

@ -14,7 +14,7 @@ redcap_output_csv1 <- REDCap_split(records, metadata)
# Test that basic CSV export matches reference ------------------------------ # Test that basic CSV export matches reference ------------------------------
test_that("CSV export matches reference", { test_that("CSV export matches reference", {
expect_known_hash(redcap_output_csv1, "f74558d1939c17d9ff0e08a19b956e26") expect_known_hash(redcap_output_csv1, "cb5074a06e1abcf659d60be1016965d2")
}) })
# Test that REDCap_split can handle a focused dataset # Test that REDCap_split can handle a focused dataset
@ -41,7 +41,7 @@ if (requireNamespace("Hmisc", quietly = TRUE)) {
redcap_output_csv2 <- redcap_output_csv2 <-
REDCap_split(REDCap_process_csv(records), metadata) REDCap_split(REDCap_process_csv(records), metadata)
expect_known_hash(redcap_output_csv2, "6d8d0462ab2343b848a086ab06b50fe3") expect_known_hash(redcap_output_csv2, "578dc054e59ec92a21e950042e08ee37")
}) })
} }

View File

@ -33,7 +33,7 @@ redcapcast_meta |> gt::gt()
``` ```
```{r} ```{r}
list <- list <-
REDCapCAST::REDCap_split(records = redcapcast_data, REDCap_split(records = redcapcast_data,
metadata = redcapcast_meta, metadata = redcapcast_meta,
forms = "repeating") forms = "repeating")
str(list) str(list)
@ -41,7 +41,7 @@ str(list)
```{r} ```{r}
list <- list <-
REDCapCAST::REDCap_split(records = redcapcast_data, REDCap_split(records = redcapcast_data,
metadata = redcapcast_meta, metadata = redcapcast_meta,
forms = "all") forms = "all")
str(list) str(list)
@ -49,14 +49,12 @@ str(list)
## Reading data from REDCap ## Reading data from REDCap
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. 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. It just cuts outs all the steps for an easier approach.
The function works very similar to the `REDCapR::redcap_read()`. The function works very similar to the `REDCapR::redcap_read()` in allowing to specify fields, events and forms for export instead of exporting the whole database and filtering afterwards. I believe this is a better and safer, focused approach.
```{r eval=FALSE} ```{r eval=FALSE}
# read_redcap_tables(uri = "YOUR URI", token = "YOUR TOKEN") # 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 ## Pivotting to wider format