minor adjustments and bug fixing

This commit is contained in:
Andreas Gammelgaard Damsbo 2024-11-21 11:18:38 +01:00
commit 40d95e41c3
No known key found for this signature in database
14 changed files with 256 additions and 71 deletions

20
man/all_na.Rd Normal file
View file

@ -0,0 +1,20 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ds2dd_detailed.R
\name{all_na}
\alias{all_na}
\title{Check if vector is all NA}
\usage{
all_na(data)
}
\arguments{
\item{data}{vector of data.frame}
}
\value{
logical
}
\description{
Check if vector is all NA
}
\examples{
rep(NA,4) |> all_na()
}

31
man/compact_vec.Rd Normal file
View file

@ -0,0 +1,31 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ds2dd_detailed.R
\name{compact_vec}
\alias{compact_vec}
\title{Compacting a vector of any length with or without names}
\usage{
compact_vec(data, nm.sep = ": ", val.sep = "; ")
}
\arguments{
\item{data}{vector, optionally named}
\item{nm.sep}{string separating name from value if any}
\item{val.sep}{string separating values}
}
\value{
character string
}
\description{
Compacting a vector of any length with or without names
}
\examples{
sample(seq_len(4), 20, TRUE) |>
as_factor() |>
named_levels() |>
sort() |>
compact_vec()
1:6 |> compact_vec()
"test" |> compact_vec()
sample(letters[1:9], 20, TRUE) |> compact_vec()
}

View file

@ -75,10 +75,15 @@ 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()
## Basic parsing with default options
REDCapCAST::redcapcast_data |>
dplyr::select(-dplyr::starts_with("redcap_")) |>
ds2dd_detailed()
## Adding a record_id field
iris |> ds2dd_detailed(add.auto.id = TRUE)
## Passing form name information to function
iris |>
ds2dd_detailed(
add.auto.id = TRUE,
@ -86,6 +91,8 @@ iris |>
) |>
purrr::pluck("meta")
mtcars |> ds2dd_detailed(add.auto.id = TRUE)
## Using column name suffix to carry form name
data <- iris |>
ds2dd_detailed(add.auto.id = TRUE) |>
purrr::pluck("data")
@ -93,4 +100,3 @@ 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

@ -33,9 +33,7 @@ data.frame or tibble
Helper to auto-parse un-formatted data with haven and readr
}
\examples{
\dontrun{
mtcars |>
parse_data() |>
str()
}
}

22
man/possibly_roman.Rd Normal file
View file

@ -0,0 +1,22 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/as_factor.R
\name{possibly_roman}
\alias{possibly_roman}
\title{Test if vector can be interpreted as roman numerals}
\usage{
possibly_roman(data)
}
\arguments{
\item{data}{character vector}
}
\value{
logical
}
\description{
Test if vector can be interpreted as roman numerals
}
\examples{
sample(1:100,10) |> as.roman() |> possibly_roman()
sample(c(TRUE,FALSE),10,TRUE)|> possibly_roman()
rep(NA,10)|> possibly_roman()
}

View file

@ -19,7 +19,6 @@ 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()
@ -28,4 +27,3 @@ sample(letters, 20) |>
summary()
sample(letters[1:4], 20, TRUE) |> var2fct(6)
}
}

24
man/vec2choice.Rd Normal file
View file

@ -0,0 +1,24 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ds2dd_detailed.R
\name{vec2choice}
\alias{vec2choice}
\title{Named vector to REDCap choices (`wrapping compact_vec()`)}
\usage{
vec2choice(data)
}
\arguments{
\item{data}{named vector}
}
\value{
character string
}
\description{
Named vector to REDCap choices (`wrapping compact_vec()`)
}
\examples{
sample(seq_len(4), 20, TRUE) |>
as_factor() |>
named_levels() |>
sort() |>
vec2choice()
}