stringr
stringr copied to clipboard
str_wrap() not splitting at specified width for long chemical name string
This is a weird string, but regardless str_wrap()
is failing to split part of it at the specified width:
library(tidyverse)
str_wrap("2-Propenoic acid, 1,1'-[2-[[(1-oxo-2-propen-1-yl)oxy]methyl]-2-[[[[[[1,3,3-trimethyl-5-[[[3-[(1-oxo-2-propen-1-yl)oxy]-2,2-bis[[(1-oxo-2-propen-1-yl)oxy]methyl]propoxy]carbonyl]amino]cyclohexyl]methyl]amino]carbonyl]oxy]methyl]-1,3-propanediyl] ester", width = 50) %>%
enframe(name = NULL) %>%
separate_rows(value, sep = "\n") %>%
mutate(chars = nchar(value))
#> # A tibble: 5 × 2
#> value chars
#> <chr> <int>
#> 1 2-Propenoic acid, 1,1'-[2-[[(1-oxo-2-propen-1- 46
#> 2 yl)oxy]methyl]-2-[[[[[[1,3,3-trimethyl-5-[[[3-[(1- 50
#> 3 oxo-2-propen-1-yl)oxy]-2,2-bis[[(1-oxo-2-propen-1- 50
#> 4 yl)oxy]methyl]propoxy]carbonyl]amino]cyclohexyl]methyl]amino]carbonyl]o… 86
#> 5 propanediyl] ester 18
You might want to use whitespace_only = FALSE