Display a counter for loops across one display line

I am running loops in R of the following variety:

for(i in 1:N){...}

I would like to have a counter that displays the current value of i in the progress of the loop. I want this to keep track of how far along I am toward reaching the end of the loop. One way to do this is to simply insert print(i) into the loop code. E.g.,

for(i in 1:N){
...substantive code that does not print anything...
print(i)
}

This does the job, giving you the i's that is running. The problem is that it prints each value on a new line, a la,

[1] 1
[1] 2
[1] 3

This eats up lots of console space; if N is large it will eat up all the console space. I would like to have a counter that does not eat up so much console space. (Sometimes it's nice to be able to scroll up the console to check to be sure you are running what you think you are running.) So, I'd like to have a counter that displays as,

[1] 1 2 3 ...

continuing onto a new line once the console width has been reached. I have seen this from time to time. Any tricks for making that happen?

7
задан zx8754 3 June 2016 в 19:55
поделиться