mirror of
https://github.com/agdamsbo/REDCapCAST.git
synced 2026-06-19 13:17:30 +02:00
executing examples with as_factor() errors. I think due to redundancy. Will investigate.
This commit is contained in:
parent
69e1520aff
commit
c86ae9a364
13 changed files with 58 additions and 24 deletions
|
|
@ -36,6 +36,7 @@ Please refer to parent functions for extended documentation.
|
|||
}
|
||||
\examples{
|
||||
# will preserve all attributes but class
|
||||
\dontrun{
|
||||
c(1, 4, 3, "A", 7, 8, 1) |> as_factor()
|
||||
structure(c(1, 2, 3, 2, 10, 9),
|
||||
labels = c(Unknown = 9, Refused = 10)
|
||||
|
|
@ -47,5 +48,5 @@ structure(c(1, 2, 3, 2, 10, 9),
|
|||
class = "haven_labelled"
|
||||
) |>
|
||||
as_factor()
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ Ensure, that the data set is formatted with as much information as possible.
|
|||
`field.type` can be supplied
|
||||
}
|
||||
\examples{
|
||||
\dontrun{
|
||||
data <- REDCapCAST::redcapcast_data
|
||||
data |> ds2dd_detailed()
|
||||
iris |> ds2dd_detailed(add.auto.id = TRUE)
|
||||
|
|
@ -92,3 +93,4 @@ names(data) <- glue::glue("{sample(x = c('a','b'),size = length(names(data)),
|
|||
replace=TRUE,prob = rep(x=.5,2))}__{names(data)}")
|
||||
data |> ds2dd_detailed(form.sep = "__")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ numeric vector
|
|||
Allows conversion of factor to numeric values preserving original levels
|
||||
}
|
||||
\examples{
|
||||
\dontrun{
|
||||
c(1, 4, 3, "A", 7, 8, 1) |>
|
||||
as_factor() |> fct2num()
|
||||
|
||||
|
|
@ -31,4 +32,5 @@ structure(c(1, 2, 3, 2, 10, 9),
|
|||
) |>
|
||||
as_factor() |>
|
||||
fct2num()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,9 +19,10 @@ Extract attribute. Returns NA if none
|
|||
}
|
||||
\examples{
|
||||
attr(mtcars$mpg, "label") <- "testing"
|
||||
sapply(mtcars, get_attr)
|
||||
lapply(mtcars, \(.x)get_attr(.x, NULL))
|
||||
do.call(c,sapply(mtcars, get_attr))
|
||||
\dontrun{
|
||||
mtcars |>
|
||||
numchar2fct(numeric.threshold = 6) |>
|
||||
ds2dd_detailed()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,11 @@ named_levels(data, label = "labels", na.label = NULL, na.value = 99)
|
|||
\item{data}{factor}
|
||||
|
||||
\item{label}{character string of attribute with named vector of factor labels}
|
||||
|
||||
\item{na.label}{character string to refactor NA values. Default is NULL.}
|
||||
|
||||
\item{na.value}{new value for NA strings. Ignored if na.label is NULL.
|
||||
Default is 99.}
|
||||
}
|
||||
\value{
|
||||
named vector
|
||||
|
|
@ -18,8 +23,10 @@ named vector
|
|||
Get named vector of factor levels and values
|
||||
}
|
||||
\examples{
|
||||
\dontrun{
|
||||
structure(c(1, 2, 3, 2, 10, 9),
|
||||
labels = c(Unknown = 9, Refused = 10),
|
||||
class = "haven_labelled"
|
||||
) |> as_factor() |> named_levels()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,9 @@ Individual thresholds for character and numeric columns
|
|||
}
|
||||
\examples{
|
||||
mtcars |> str()
|
||||
\dontrun{
|
||||
mtcars |>
|
||||
numchar2fct(numeric.threshold = 6) |>
|
||||
str()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,9 @@ data.frame or tibble
|
|||
Helper to auto-parse un-formatted data with haven and readr
|
||||
}
|
||||
\examples{
|
||||
\dontrun{
|
||||
mtcars |>
|
||||
parse_data() |>
|
||||
str()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
\alias{set_attr}
|
||||
\title{Set attributes for named attribute. Appends if attr is NULL}
|
||||
\usage{
|
||||
set_attr(data, label, attr = NULL)
|
||||
set_attr(data, label, attr = NULL, overwrite = FALSE)
|
||||
}
|
||||
\arguments{
|
||||
\item{data}{vector}
|
||||
|
|
@ -12,6 +12,8 @@ set_attr(data, label, attr = NULL)
|
|||
\item{label}{label}
|
||||
|
||||
\item{attr}{attribute name}
|
||||
|
||||
\item{overwrite}{overwrite existing attributes. Default is FALSE.}
|
||||
}
|
||||
\value{
|
||||
vector with attribute
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ This is a wrapper of forcats::as_factor, which sorts numeric vectors before
|
|||
factoring, but levels character vectors in order of appearance.
|
||||
}
|
||||
\examples{
|
||||
\dontrun{
|
||||
sample(seq_len(4), 20, TRUE) |>
|
||||
var2fct(6) |>
|
||||
summary()
|
||||
|
|
@ -27,3 +28,4 @@ sample(letters, 20) |>
|
|||
summary()
|
||||
sample(letters[1:4], 20, TRUE) |> var2fct(6)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue