I'm currently running a for loop code and at the end of each loop I am measuring the duration of the loop and print a message that tells the user how long did the loop take.
To get the duration I'm using
duration <- difftime(end_time, start_time)
And this is how I print the statement
print(paste("Loop", i, "took", duration, "to run.")).
The problem is the duration of each loop may range from 30 seconds to 1 hour. Putting the duration inside the paste just turns it into a number without the unit in it.
e.g.
print(paste("Loop", i, "took", duration, "to run.")).
"Loop 5 took 10.5 to run"
How do I get the unit from the difftime() in order to get something like: "Loop 5 took 10.5 minutes to run."
PS: Some may suggest standardizing the duration by declaring the "unit" argument in difftime() but I want the duration to be easily understood by the user that's why I set the unit to default "auto".