mirror of
https://github.com/agdamsbo/REDCapCAST.git
synced 2024-11-22 13:30:23 +01:00
Cleaning up R code and adding RStudio project.
This commit is contained in:
parent
f25319366c
commit
cbc39e288e
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
*.html
|
*.html
|
||||||
.Rhistory
|
.Rhistory
|
||||||
|
.Rproj.user
|
||||||
|
16
REDCapRITS.Rproj
Normal file
16
REDCapRITS.Rproj
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
Version: 1.0
|
||||||
|
|
||||||
|
RestoreWorkspace: Default
|
||||||
|
SaveWorkspace: Default
|
||||||
|
AlwaysSaveHistory: Default
|
||||||
|
|
||||||
|
EnableCodeIndexing: Yes
|
||||||
|
UseSpacesForTab: Yes
|
||||||
|
NumSpacesForTab: 2
|
||||||
|
Encoding: UTF-8
|
||||||
|
|
||||||
|
RnwWeave: Sweave
|
||||||
|
LaTeX: pdfLaTeX
|
||||||
|
|
||||||
|
AutoAppendNewline: Yes
|
||||||
|
StripTrailingWhitespace: Yes
|
@ -1,7 +1,6 @@
|
|||||||
# v0.0.0
|
|
||||||
#' Split REDCap repeating instruments table into multiple tables
|
#' Split REDCap repeating instruments table into multiple tables
|
||||||
#'
|
#'
|
||||||
#' This will take a raw data frame from REDCap and split it into a base table
|
#' This will take a raw \code{data.frame} from REDCap and split it into a base table
|
||||||
#' and give individual tables for each repeating instrument. Metadata
|
#' and give individual tables for each repeating instrument. Metadata
|
||||||
#' is used to determine which fields should be included in each resultant table.
|
#' is used to determine which fields should be included in each resultant table.
|
||||||
#'
|
#'
|
||||||
@ -45,25 +44,28 @@
|
|||||||
#' @export
|
#' @export
|
||||||
REDCap_split <- function(records, metadata) {
|
REDCap_split <- function(records, metadata) {
|
||||||
|
|
||||||
|
stopifnot(all(sapply(list(records,metadata), inherits, "data.frame")))
|
||||||
|
|
||||||
# Check to see if there were any repeating instruments
|
# Check to see if there were any repeating instruments
|
||||||
|
|
||||||
if (!any(names(records) == "redcap_repeat_instrument")) {
|
if (!any(names(records) == "redcap_repeat_instrument")) {
|
||||||
|
|
||||||
warning("There are no repeating instruments.\n")
|
message("There are no repeating instruments in this data.")
|
||||||
|
|
||||||
return(list(records))
|
return(list(records))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Clean the metadata
|
# Clean the metadata
|
||||||
metadata <- metadata[metadata["field_type"] != "descriptive", 1:4]
|
metadata <-
|
||||||
|
metadata[metadata$field_type != "descriptive", c("field_name", "form_name")]
|
||||||
|
|
||||||
# Identify the subtables in the data
|
# Identify the subtables in the data
|
||||||
subtables <- unique(records["redcap_repeat_instrument"])
|
subtables <- unique(records$redcap_repeat_instrument)
|
||||||
subtables <- subtables[subtables != ""]
|
subtables <- subtables[subtables != ""]
|
||||||
|
|
||||||
# Split the table based on instrument
|
# Split the table based on instrument
|
||||||
out <- split.data.frame(records, records["redcap_repeat_instrument"])
|
out <- split.data.frame(records, records$redcap_repeat_instrument)
|
||||||
|
|
||||||
# Delete the variables that are not relevant
|
# Delete the variables that are not relevant
|
||||||
for (i in names(out)) {
|
for (i in names(out)) {
|
||||||
@ -71,7 +73,7 @@ REDCap_split <- function(records, metadata) {
|
|||||||
if (i == "") {
|
if (i == "") {
|
||||||
|
|
||||||
out[[which(names(out) == "")]] <-
|
out[[which(names(out) == "")]] <-
|
||||||
out[[which(names(out) == "")]][metadata[`!`(metadata[,2] %in% subtables), 1]]
|
out[[which(names(out) == "")]][metadata[!metadata[,2] %in% subtables, 1]]
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user