new functionds2dd_detailed()which includes more details than the old ds2dd().

This commit is contained in:
Andreas Gammelgaard Damsbo 2024-01-18 14:57:12 +01:00
commit 21e635d775
8 changed files with 534 additions and 4 deletions

View file

@ -2,7 +2,7 @@
% Please edit documentation in R/ds2dd.R
\name{ds2dd}
\alias{ds2dd}
\title{Data set to data dictionary function}
\title{(DEPRECATED) Data set to data dictionary function}
\usage{
ds2dd(
ds,
@ -11,7 +11,7 @@ ds2dd(
field.type = "text",
field.label = NULL,
include.column.names = FALSE,
metadata = names(redcapcast_meta)
metadata = metadata_names
)
}
\arguments{
@ -34,14 +34,18 @@ names.}
column names for original data set for upload.}
\item{metadata}{Metadata column names. Default is the included
REDCapCAST::redcapcast_data.}
REDCapCAST::metadata_names.}
}
\value{
data.frame or list of data.frame and vector
}
\description{
Creates a very basic data dictionary skeleton. Please see `ds2dd_detailed()`
for a more advanced function.
}
\details{
Migrated from stRoke ds2dd(). Fits better with the functionality of
'REDCapCAST'
'REDCapCAST'.
}
\examples{
redcapcast_data$record_id <- seq_len(nrow(redcapcast_data))

82
man/ds2dd_detailed.Rd Normal file
View file

@ -0,0 +1,82 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ds2dd_detailed.R
\name{ds2dd_detailed}
\alias{ds2dd_detailed}
\title{Extract data from stata file for data dictionary}
\usage{
ds2dd_detailed(
data,
add.auto.id = FALSE,
date.format = "dmy",
form.name = NULL,
field.type = NULL,
field.label = NULL,
field.label.attr = "label",
field.validation = NULL,
metadata = metadata_names,
validate.time = FALSE,
time.var.sel.pos = "[Tt]i[d(me)]",
time.var.sel.neg = "[Dd]at[eo]"
)
}
\arguments{
\item{data}{data frame}
\item{add.auto.id}{flag to add id column}
\item{date.format}{date format, character string. ymd/dmy/mdy. dafault is
dmy.}
\item{form.name}{manually specify form name(s). Vector of length 1 or
ncol(data). Default is NULL and "data" is used.}
\item{field.type}{manually specify field type(s). Vector of length 1 or
ncol(data). Default is NULL and "text" is used for everything but factors,
which wil get "radio".}
\item{field.label}{manually specify field label(s). Vector of length 1 or
ncol(data). Default is NULL and colnames(data) is used or attribute
`field.label.attr` for haven_labelled data set (imported .dta file with
`haven::read_dta()`).}
\item{field.label.attr}{attribute name for named labels for haven_labelled
data set (imported .dta file with `haven::read_dta()`. Default is "label"}
\item{field.validation}{manually specify field validation(s). Vector of
length 1 or ncol(data). Default is NULL and `levels()` are used for factors
or attribute `factor.labels.attr` for haven_labelled data set (imported .dta file with
`haven::read_dta()`).}
\item{metadata}{redcap metadata headings. Default is
REDCapCAST:::metadata_names.}
\item{validate.time}{Flag to validate guessed time columns}
\item{time.var.sel.pos}{Positive selection regex string passed to
`gues_time_only_filter()` as sel.pos.}
\item{time.var.sel.neg}{Negative selection regex string passed to
`gues_time_only_filter()` as sel.neg.}
}
\value{
list of length 2
}
\description{
Extract data from stata file for data dictionary
}
\details{
This function is a natural development of the ds2dd() function. It assumes
that the first column is the ID-column. No checks.
Please, do always inspect the data dictionary before upload.
Ensure, that the data set is formatted with as much information as possible.
`field.type` can be supplied
}
\examples{
data <- redcapcast_data
data |> ds2dd_detailed(validate.time = TRUE)
data |> ds2dd_detailed()
iris |> ds2dd_detailed(add.auto.id = TRUE)
mtcars |> ds2dd_detailed(add.auto.id = TRUE)
}

View file

@ -0,0 +1,36 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ds2dd_detailed.R
\name{guess_time_only_filter}
\alias{guess_time_only_filter}
\title{Try at determining which are true time only variables}
\usage{
guess_time_only_filter(
data,
validate = FALSE,
sel.pos = "[Tt]i[d(me)]",
sel.neg = "[Dd]at[eo]"
)
}
\arguments{
\item{data}{data set}
\item{validate}{flag to output validation data. Will output list.}
\item{sel.pos}{Positive selection regex string}
\item{sel.neg}{Negative selection regex string}
}
\value{
character vector or list depending on `validate` flag.
}
\description{
This is just a try at guessing data type based on data class and column names
hoping for a tiny bit of naming consistency. R does not include a time-only
data format natively, so the "hms" class from `readr` is used. This
has to be converted to character class before REDCap upload.
}
\examples{
data <- redcapcast_data
data |> guess_time_only_filter()
data |> guess_time_only_filter(validate = TRUE) |> lapply(head)
}

21
man/hms2character.Rd Normal file
View file

@ -0,0 +1,21 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ds2dd_detailed.R
\name{hms2character}
\alias{hms2character}
\title{Change "hms" to "character" for REDCap upload.}
\usage{
hms2character(data)
}
\arguments{
\item{data}{data set}
}
\value{
data.frame or tibble
}
\description{
Change "hms" to "character" for REDCap upload.
}
\examples{
data <- redcapcast_data
## data |> time_only_correction() |> hms2character()
}

19
man/mark_complete.Rd Normal file
View file

@ -0,0 +1,19 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ds2dd_detailed.R
\name{mark_complete}
\alias{mark_complete}
\title{Completion marking based on completed upload}
\usage{
mark_complete(upload, ls)
}
\arguments{
\item{upload}{output list from `REDCapR::redcap_write()`}
\item{ls}{output list from `ds2dd_detailed()`}
}
\value{
list with `REDCapR::redcap_write()` results
}
\description{
Completion marking based on completed upload
}

View file

@ -0,0 +1,25 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ds2dd_detailed.R
\name{time_only_correction}
\alias{time_only_correction}
\title{Correction based on time_only_filter function. Introduces new class for easier
validation labelling.}
\usage{
time_only_correction(data, ...)
}
\arguments{
\item{data}{data set}
\item{...}{arguments passed on to `guess_time_only_filter()`}
}
\value{
tibble
}
\description{
Dependens on the data class "hms" introduced with
`guess_time_only_filter()` and converts these
}
\examples{
data <- redcapcast_data
## data |> time_only_correction()
}