SOLUTION:
I follow the function presented in this post from @mara (thanks so much!)
The entire pipe is presented below for completeness:
strsplit_keep <- function(x,
split,
type = "remove",
perl = FALSE,
...) {
if (type == "remove") {
# use base::strsplit
out <- base::strsplit(x = x, split = split, perl = perl, ...)
} else if (type == "before") {
# split before the delimiter and keep it
out <- base::strsplit(x = x,
split = paste0("(?<=.)(?=", split, ")"),
perl = TRUE,
...)
} else if (type == "after") {
# split after the delimiter and keep it
out <- base::strsplit(x = x,
split = paste0("(?<=", split, ")"),
perl = TRUE,
...)
} else {
# wrong type input
stop("type must be remove, after or before!")
}
return(out)
}
now this works (with some additional wrangling).
strsplit_keep(x = string_vector,
split = "\\d\\d:\\d\\d",
type = "before") %>%
as_tibble(.name_repair = "unique") %>%
# rename this variable to orginal_record
dplyr::rename(orginal_record = `...1`) %>%
# create a dummy variable but keep the time
tidyr::separate(col = orginal_record,
into = c("time", "dummy"),
sep = " ",
remove = FALSE) %>%
# now remove time from orginal_record
dplyr::mutate(description = stringr::str_remove_all(string = orginal_record,
pattern = "(\\d\\d:\\d\\d)")) %>%
# drop dummy!
dplyr::select(-dummy)
#> # A tibble: 3 x 3
#> orginal_record time description
#> <chr> <chr> <chr>
#> 1 05:52 The birch canoe slid on the … 05:52 " The birch canoe slid on the …
#> 2 05:53 These days a chicken leg is … 05:53 " These days a chicken leg is …
#> 3 06:59 Four hours of steady work fa… 06:59 " Four hours of steady work fa…
Created on 2019-04-10 by the reprex package (v0.2.1)