R/strsplit_that_works.R

Defines functions strsplit_that_works

Documented in strsplit_that_works

#' @title strsplit_that_works
#' @description We got tired of having to work with splitting strings in weird ways.
#' @param cell the string you want to split
#' @param entity_requested a number representing the
#' @param split split used in strsplit Default: '_'
#' @details Returns only the part of a string as designated by entity_requested
#' @examples
#' \dontrun{
#' try <- ("1_2_3_4")
#' strsplit_that_works(try, 1, split = "_")
#'
#' library(tidyverse)
#' tidyr::table3 %>%
#'   mutate(map_chr(rate, first_part = strsplit_that_works, 1, split = "/"))
#' }
#' @export

strsplit_that_works <- function(cell, entity_requested, split = "_") {
  x <- strsplit(cell, split = split)
  y <- x[[1]][entity_requested]
  return(y)
}
eringrand/RUncommon documentation built on Sept. 22, 2020, 10:49 p.m.