Skip to content

Commit

Permalink
Merge pull request #911 from salix-d/gnr_resolve-issue-#904
Browse files Browse the repository at this point in the history
Fix the encoding issue in gnr_resolve (update to taxize_capwords)
  • Loading branch information
zachary-foster committed May 2, 2023
2 parents 487ca29 + b472e5d commit 2690950
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions R/taxize_capwords.r
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
#' taxize_capwords(c("using AIC for model selection"), strict=TRUE)

taxize_capwords <- function(s, strict = FALSE, onlyfirst = FALSE) {
cap <- function(s) {
paste(toupper(substring(s,1,1)), {
s <- substring(s,2); if (strict) tolower(s) else s
}, sep = "", collapse = " " )
}

if (!onlyfirst) {
sapply(strsplit(s, split = " "), cap, USE.NAMES = !is.null(names(s)))
if (onlyfirst) {
if (strict) {
gsub("^(.)(.*)$", "\\U\\1\\L\\2", s, perl = TRUE)
} else {
gsub("^(.)", "\\U\\1", s, perl = TRUE)
}
} else {
sapply(s, function(x)
paste(toupper(substring(x,1,1)),
tolower(substring(x,2)),
sep = "", collapse = " "), USE.NAMES = FALSE)
if (strict) {
gsub("(?<=^| )(.)(.*)(?=$| )", "\\U\\1\\L\\2", s, perl = TRUE)
} else {
gsub("(?<=^| )(.)", "\\U\\1", s, perl = TRUE)
}

}
}

0 comments on commit 2690950

Please sign in to comment.