mirror of
https://github.com/agdamsbo/REDCapCAST.git
synced 2024-10-30 03:21:53 +01:00
a new helper function has been introduced to help matching form names when special characters are in use.
This commit is contained in:
parent
4847094f2c
commit
563c864091
|
@ -88,13 +88,17 @@ REDCap_split <- function(records,
|
||||||
# Process user input
|
# Process user input
|
||||||
records <- process_user_input(records)
|
records <- process_user_input(records)
|
||||||
metadata <-
|
metadata <-
|
||||||
as.data.frame(process_user_input(metadata)) # See issue #12
|
as.data.frame(process_user_input(metadata))
|
||||||
|
|
||||||
|
# Process repeat instrument names to match the redcap naming
|
||||||
|
records$redcap_repeat_instrument <- clean_redcap_name(records$redcap_repeat_instrument)
|
||||||
|
|
||||||
|
|
||||||
# Get the variable names in the dataset
|
# Get the variable names in the dataset
|
||||||
vars_in_data <- names(records)
|
vars_in_data <- names(records)
|
||||||
|
|
||||||
# Match arg for forms
|
# Match arg for forms
|
||||||
forms <- match.arg(forms)
|
forms <- match.arg(forms, c("repeating", "all"))
|
||||||
|
|
||||||
# Check to see if there were any repeating instruments
|
# Check to see if there were any repeating instruments
|
||||||
if (forms == "repeating" &&
|
if (forms == "repeating" &&
|
||||||
|
|
|
@ -76,8 +76,7 @@ read_redcap_tables <- function(uri,
|
||||||
# Removes any extra characters other than a-z, 0-9 and "_", to mimic raw
|
# Removes any extra characters other than a-z, 0-9 and "_", to mimic raw
|
||||||
# instrument names.
|
# instrument names.
|
||||||
if ("redcap_repeat_instrument" %in% names(d)) {
|
if ("redcap_repeat_instrument" %in% names(d)) {
|
||||||
d$redcap_repeat_instrument <-
|
d$redcap_repeat_instrument <- clean_redcap_name(d$redcap_repeat_instrument)
|
||||||
gsub("[^a-z0-9_]", "", gsub(" ", "_", tolower(d$redcap_repeat_instrument)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Getting metadata
|
# Getting metadata
|
||||||
|
@ -93,7 +92,7 @@ read_redcap_tables <- function(uri,
|
||||||
l <- REDCap_split(d,
|
l <- REDCap_split(d,
|
||||||
m,
|
m,
|
||||||
forms = split_forms,
|
forms = split_forms,
|
||||||
primary_table_name = "nonrepeating")
|
primary_table_name = "")
|
||||||
|
|
||||||
# Sanitizing split list by removing completely empty rows apart from colnames
|
# Sanitizing split list by removing completely empty rows apart from colnames
|
||||||
# in "generics"
|
# in "generics"
|
||||||
|
|
19
R/utils.r
19
R/utils.r
|
@ -83,9 +83,24 @@ focused_metadata <- function(metadata, vars_in_data) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#' clean_redcap_name
|
||||||
|
#' @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.
|
||||||
|
#'
|
||||||
|
#' @param x vector or data frame for cleaning
|
||||||
|
#'
|
||||||
|
#' @return vector or data frame, same format as input
|
||||||
|
#' @export
|
||||||
|
#'
|
||||||
|
clean_redcap_name <- function(x){
|
||||||
|
|
||||||
|
gsub(" ", "_",
|
||||||
# function to convert the list of dataframes
|
gsub("[' ']$","",
|
||||||
|
gsub("[^a-z0-9' '_]", "",
|
||||||
|
tolower(x)
|
||||||
|
)))}
|
||||||
|
|
||||||
|
|
||||||
#' Sanitize list of data frames
|
#' Sanitize list of data frames
|
||||||
|
|
Loading…
Reference in New Issue
Block a user