-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#' Correct species binomial name case | ||
#' | ||
#' @description | ||
#' Corrects species binomial name case. | ||
#' | ||
#' @param x a `character` vector with misspelled binomial names. | ||
#' | ||
#' @return A `character` vector of same length as `x`. | ||
#' | ||
#' @export | ||
#' | ||
#' @examples | ||
#' x <- c("sAlMO saLAR (Linnee, 1765)", "tyranosurus_REX rex.1") | ||
#' to_binomial_name(x) | ||
|
||
to_binomial_name <- function(x) { | ||
|
||
if (missing(x)) { | ||
stop("Argument 'x' is required", call. = FALSE) | ||
} | ||
|
||
if (!is.character(x)) { | ||
stop("Argument 'x' must be a character", call. = FALSE) | ||
} | ||
|
||
|
||
## Remove author and year ---- | ||
|
||
x <- gsub("\\(.+\\)", "", x) | ||
|
||
|
||
## Clean string ---- | ||
|
||
x <- gsub("[[:punct:]]|[[:digit:]]", " ", x) | ||
x <- gsub("\\s+", " ", x) | ||
x <- trimws(x) | ||
|
||
|
||
## Correct case ---- | ||
|
||
x <- tolower(x) | ||
substr(x, 1, 1) <- toupper(substr(x, 1, 1)) | ||
|
||
x | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.