Hello,
I'm wondering if anyone knows why the RStudio console is having issues with properly wrapping long strings of text of various characters.
Let me show by example: using the cli::console_width() function, we can get the "exact" width in characters of the console. Actually, you have to add 3 if you're not counting the default >
that's displayed.
My console has as width of 89 (89+3) and I'm generating one long string of 5x89 characters and using cat to display it in the console. Then I do the same thing, but I paste 5 strings of 89 together with a linebreak (\n) and then use cat
#Console width = 89
set.seed(10)
sample(c("*", "."), (cli::console_width()+3)*5,
replace = T) %>% paste0(collapse = "") %>% cat("\n")
sapply(1:5, function(x){
sample(c("*", "."), (cli::console_width()+3),
replace = T) %>% paste0(collapse = "")}) %>%
paste(collapse = "\n") %>% cat()
OUTPUT in console
Note how in the first instance, the wrapping is not correct and is generating incomplete lines with overflow into a 6th line. The number of characters in both is exactly the same, but the wrapping goes wrong.
I have tested this in other consoles (not RStudio) and this problem never occurs. Interestingly, if the characters are all the same, the wrapping issue is not present:
The characters are in a monospace font (you can see that they are aligned even when different) so this should not be the explanation...
Any ideas?
PJ