major update with new functions and renv is out! see NEWS section

This commit is contained in:
Andreas Gammelgaard Damsbo 2024-06-07 10:35:16 +02:00
commit 4a56f4ec45
16 changed files with 158 additions and 93 deletions

View file

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