mirror of
https://github.com/agdamsbo/REDCapCAST.git
synced 2026-06-19 05:07:30 +02:00
implement support for variable attributes for field label incl conversion of logicals to factor
This commit is contained in:
parent
f2b2784547
commit
fe9918dc10
6 changed files with 132 additions and 11 deletions
|
|
@ -15,7 +15,8 @@ ds2dd_detailed(
|
|||
field.label = NULL,
|
||||
field.label.attr = "label",
|
||||
field.validation = NULL,
|
||||
metadata = names(REDCapCAST::redcapcast_meta)
|
||||
metadata = names(REDCapCAST::redcapcast_meta),
|
||||
convert.logicals = TRUE
|
||||
)
|
||||
}
|
||||
\arguments{
|
||||
|
|
@ -55,6 +56,8 @@ file with `haven::read_dta()`).}
|
|||
|
||||
\item{metadata}{redcap metadata headings. Default is
|
||||
REDCapCAST:::metadata_names.}
|
||||
|
||||
\item{convert.logicals}{convert logicals to factor. Default is TRUE.}
|
||||
}
|
||||
\value{
|
||||
list of length 2
|
||||
|
|
|
|||
27
man/get_attr.Rd
Normal file
27
man/get_attr.Rd
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/ds2dd_detailed.R
|
||||
\name{get_attr}
|
||||
\alias{get_attr}
|
||||
\title{Extract attribute. Returns NA if none}
|
||||
\usage{
|
||||
get_attr(data, attr = NULL)
|
||||
}
|
||||
\arguments{
|
||||
\item{data}{vector}
|
||||
|
||||
\item{attr}{attribute name}
|
||||
}
|
||||
\value{
|
||||
character vector
|
||||
}
|
||||
\description{
|
||||
Extract attribute. Returns NA if none
|
||||
}
|
||||
\examples{
|
||||
attr(mtcars$mpg, "label") <- "testing"
|
||||
sapply(mtcars, get_attr)
|
||||
lapply(mtcars, \(.x)get_attr(.x, NULL))
|
||||
mtcars |>
|
||||
numchar2fct(numeric.threshold = 6) |>
|
||||
ds2dd_detailed()
|
||||
}
|
||||
|
|
@ -20,5 +20,7 @@ ds <- structure(c(1, 2, 3, 2, 10, 9),
|
|||
labels = c(Unknown = 9, Refused = 10),
|
||||
class = "haven_labelled"
|
||||
)
|
||||
labelled::is.labelled(ds)
|
||||
attributes(ds)
|
||||
ds |> haven_all_levels()
|
||||
}
|
||||
|
|
|
|||
21
man/set_attr.Rd
Normal file
21
man/set_attr.Rd
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/ds2dd_detailed.R
|
||||
\name{set_attr}
|
||||
\alias{set_attr}
|
||||
\title{Set attributes for named attribute. Appends if attr is NULL}
|
||||
\usage{
|
||||
set_attr(data, label, attr = NULL)
|
||||
}
|
||||
\arguments{
|
||||
\item{data}{vector}
|
||||
|
||||
\item{label}{label}
|
||||
|
||||
\item{attr}{attribute name}
|
||||
}
|
||||
\value{
|
||||
vector with attribute
|
||||
}
|
||||
\description{
|
||||
Set attributes for named attribute. Appends if attr is NULL
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue