Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
crcruzr committed Jun 25, 2024
1 parent 22ba3c7 commit f7f6c1a
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions internals.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Function to clean species list names
#' @keywords internal
standardize_names <- function(splist) {
fixed1 <- simple_cap(trimws(splist)) # all up
fixed2 <- gsub("cf\\.", "", fixed1)
fixed3 <- gsub("aff\\.", "", fixed2)
fixed4 <- trimws(fixed3) # remove trailing and leading space
fixed5 <- gsub("_", " ", fixed4) # change names separated by _ to space

# Hybrids
fixed6 <- gsub("(^x )|( x$)|( x )", " ", fixed5)
hybrids <- fixed5 == fixed6
if (!all(hybrids)) {
sp_hybrids <- splist[!hybrids]
warning(paste("The 'x' sign indicating hybrids have been removed in the",
"following names before search:",
paste(paste0("'", sp_hybrids, "'"), collapse = ", ")),
immediate. = TRUE, call. = FALSE)
}
# Merge multiple spaces
fixed7 <- gsub("(?<=[\\s])\\s*|^\\s+|\\s+$", "", fixed6, perl = TRUE)
return(fixed7)
}

#' @keywords internal
simple_cap <- function(x) {
# Split each string into words, remove unnecessary white spaces, and convert to lowercase
words <- sapply(strsplit(x, "\\s+"), function(words) paste(tolower(words), collapse = " "))

# Capitalize the first letter of each word
capitalized <- sapply(strsplit(words, ""), function(word) {
if (length(word) > 0) {
word[1] <- toupper(word[1])
}
paste(word, collapse = "")
})

return(capitalized)
}

#' @keywords internal
#'
find_duplicates <- function(vector) {
# Count the frequency of each word
word_counts <- table(vector)
# Find words with a frequency greater than 1
duplicated_words <- names(word_counts[word_counts > 1])
return(duplicated_words)
}


0 comments on commit f7f6c1a

Please sign in to comment.