I sometimes do (nested) for
loops that take a while, so I like putting a message with the index. Normally, I do this:
for (i in 1:1000) {
cat(paste0(i, " "))
}
But I've tried any of these:
for (i in 1:1000) {
print(i)
}
for (i in 1:1000) {
cat(paste(i, " ")) # or "\n", doesn't matter
}
for (i in 1:1000) {
message(i)
}
However, this clearly produces text continuously (in this example, the messages would go by very quickly, but as I said, I often do nested for
loops, which take considerably longer). However, I'd like to do a dynamic message, with a single number on my console which keeps changing (the index). I suppose something like this is possible because when you install a package (or when using gganimate
), there is that line that keeps changing to =
signs, indicating progress (that's next-level stuff, but should have the same idea behind it).
I don't know how to do this. My guess is there's something of the same context as \n
, like \s
(I know that doesn't exist, but it's just do give an idea), or maybe there is a third function (or something related to message()
, which I don't fully understand) other than print()
, cat()
and message()
.