mirror of
https://github.com/agdamsbo/REDCapCAST.git
synced 2026-06-19 13:17:30 +02:00
major update with new functions and renv is out! see NEWS section
This commit is contained in:
parent
b35142f0cc
commit
4a56f4ec45
16 changed files with 158 additions and 93 deletions
25
R/doc2dd.R
25
R/doc2dd.R
|
|
@ -108,6 +108,9 @@ doc2dd <- function(data,
|
|||
)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
## Defining the calculations
|
||||
if (is_missing(col.calculation)) {
|
||||
out <- out |>
|
||||
|
|
@ -115,12 +118,13 @@ doc2dd <- function(data,
|
|||
calculations = missing.default
|
||||
)
|
||||
} else {
|
||||
# With inspiration from textclean package, curly apostrophe is replaced
|
||||
out <- out |>
|
||||
dplyr::mutate(
|
||||
calculations = dplyr::pick(col.calculation) |>
|
||||
unlist() |>
|
||||
tolower() |>
|
||||
(\(.x) gsub("’", "'", .x))()
|
||||
replace_curly_quote()
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -288,3 +292,22 @@ is_missing <- function(data,nas=c("", "NA")) {
|
|||
is.na(data) | data %in% nas
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#' Replace curly apostrophes and quotes from word
|
||||
#'
|
||||
#' @description
|
||||
#' Copied from textclean, which has not been updated since 2018 and is not
|
||||
#' on CRAN. Github:https://github.com/trinker/textclean
|
||||
#'
|
||||
#' @param x character vector
|
||||
#'
|
||||
#' @return character vector
|
||||
replace_curly_quote <- function(x){
|
||||
replaces <- c('\x91', '\x92', '\x93', '\x94')
|
||||
Encoding(replaces) <- "latin1"
|
||||
for (i in 1:4) {
|
||||
x <- gsub(replaces[i], c("'", "'", "\"", "\"")[i], x, fixed = TRUE)
|
||||
}
|
||||
x
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue