This question is related to my question about Roxygen.
I want to write a new function that performs word wrap for strings, similar to strwrapor stringr::str_wrap, but with the following twist: Any elements (substrings) in a string enclosed in quotation marks should not be allowed to wrap.
So, for example, using the following data examples
test <- "function(x=123456789, y=\"This is a long string argument\")"
cat(test)
function(x=123456789, y="This is a long string argument")
strwrap(test, width=40)
[1] "function(x=123456789, y=\"This is a long"
[2] "string argument\")"
I want the desired result to newWrapFunction(x, width=40, ...)be as follows:
desired <- c("function(x=123456789, ", "y=\"This is a long string argument\")")
desired
[1] "function(x=123456789, "
[2] "y=\"This is a long string argument\")"
identical(desired, newWrapFunction(tsring, width=40))
[1] TRUE
Can you come up with a way to do this?
PS. If you can help me solve this problem, I suggest this code as a patch for roxygen2. I have determined where this patch should apply and your input will be recognized.