I am trying to print text repeatedly on the same line in R (windows). This works if I use the carriage return in the following way:
text = c("word 1", "word 2", "word 3")
for (word in text) {
cat("\rText =",word)
Sys.sleep(0.4)
}
This overrides each line like it should.
However, I would like to print the words in bold and use the ANSI codes \u001b[1m
and the reset \u001b[0m
which results in:
text = c("word 1", "word 2", "word 3")
for (word in text) {
cat("\rText =\u001b[1m",word,"\u001b[0m")
Sys.sleep(0.4)
}
This works for the first two prints, but eventually results in the output:
Text =Text = word 3 Interestingly enough this does work if ALL output text is in bold font and not only part of it.
How can I get this to work?