2024-01-18 14:57:12 +01:00
|
|
|
% 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,
|
2024-04-12 12:19:56 +02:00
|
|
|
form.sep = NULL,
|
|
|
|
form.prefix = TRUE,
|
2024-01-18 14:57:12 +01:00
|
|
|
field.type = NULL,
|
|
|
|
field.label = NULL,
|
|
|
|
field.label.attr = "label",
|
|
|
|
field.validation = NULL,
|
2024-11-19 12:54:26 +01:00
|
|
|
metadata = names(REDCapCAST::redcapcast_meta),
|
|
|
|
convert.logicals = TRUE
|
2024-01-18 14:57:12 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
\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.}
|
|
|
|
|
2024-04-12 12:19:56 +02:00
|
|
|
\item{form.sep}{If supplied dataset has form names as suffix or prefix to the
|
|
|
|
column/variable names, the seperator can be specified. If supplied, the
|
2024-10-24 11:41:48 +02:00
|
|
|
form.name is ignored. Default is NULL.}
|
2024-04-12 12:19:56 +02:00
|
|
|
|
|
|
|
\item{form.prefix}{Flag to set if form is prefix (TRUE) or suffix (FALSE) to
|
|
|
|
the column names. Assumes all columns have pre- or suffix if specified.}
|
|
|
|
|
2024-01-18 14:57:12 +01:00
|
|
|
\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
|
2024-02-27 13:20:21 +01:00
|
|
|
or attribute `factor.labels.attr` for haven_labelled data set (imported .dta
|
|
|
|
file with `haven::read_dta()`).}
|
2024-01-18 14:57:12 +01:00
|
|
|
|
|
|
|
\item{metadata}{redcap metadata headings. Default is
|
|
|
|
REDCapCAST:::metadata_names.}
|
2024-11-19 12:54:26 +01:00
|
|
|
|
|
|
|
\item{convert.logicals}{convert logicals to factor. Default is TRUE.}
|
2024-01-18 14:57:12 +01:00
|
|
|
}
|
|
|
|
\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{
|
2024-11-21 11:18:38 +01:00
|
|
|
## Basic parsing with default options
|
|
|
|
REDCapCAST::redcapcast_data |>
|
|
|
|
dplyr::select(-dplyr::starts_with("redcap_")) |>
|
|
|
|
ds2dd_detailed()
|
|
|
|
|
|
|
|
## Adding a record_id field
|
2024-01-18 14:57:12 +01:00
|
|
|
iris |> ds2dd_detailed(add.auto.id = TRUE)
|
2024-11-21 11:18:38 +01:00
|
|
|
|
|
|
|
## Passing form name information to function
|
2024-10-24 11:41:48 +02:00
|
|
|
iris |>
|
|
|
|
ds2dd_detailed(
|
|
|
|
add.auto.id = TRUE,
|
|
|
|
form.name = sample(c("b", "c"), size = 6, replace = TRUE, prob = rep(.5, 2))
|
|
|
|
) |>
|
|
|
|
purrr::pluck("meta")
|
2024-01-18 14:57:12 +01:00
|
|
|
mtcars |> ds2dd_detailed(add.auto.id = TRUE)
|
2024-11-21 11:18:38 +01:00
|
|
|
|
|
|
|
## Using column name suffix to carry form name
|
2024-04-12 12:19:56 +02:00
|
|
|
data <- iris |>
|
|
|
|
ds2dd_detailed(add.auto.id = TRUE) |>
|
|
|
|
purrr::pluck("data")
|
|
|
|
names(data) <- glue::glue("{sample(x = c('a','b'),size = length(names(data)),
|
|
|
|
replace=TRUE,prob = rep(x=.5,2))}__{names(data)}")
|
2024-10-24 11:41:48 +02:00
|
|
|
data |> ds2dd_detailed(form.sep = "__")
|
2024-01-18 14:57:12 +01:00
|
|
|
}
|