Skip to content

Instantly share code, notes, and snippets.

@zdealveindy
Created December 19, 2017 12:07
Show Gist options
  • Save zdealveindy/e2ccfeba9fe1cd33ac4946afeaeaa68b to your computer and use it in GitHub Desktop.
Save zdealveindy/e2ccfeba9fe1cd33ac4946afeaeaa68b to your computer and use it in GitHub Desktop.
create.abbrev2 <- function (names, sep = '')
{
Gene <- names %>% # note Gene with uppercase G to show that beginning has uppercase lettter
str_split (' ') %>%
sapply (FUN = function (x) x[1]) %>%
str_sub (start = 1, end = 4)
spec <- names %>% # spec with lowercase s
str_split (' ') %>%
sapply (FUN = function (x) x[2]) %>%
str_sub (start = 1, end = 4)
Spec <- paste ( # Spec with uppercase S - now the abbreviation has first letter uppercase
spec %>% str_sub (start = 1, end = 1) %>% str_to_upper (),
spec %>% str_sub (start = 2, end = 4),
sep = '')
paste (Gene, Spec, sep = sep) # paste Gene and Spec together with optional separator
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment