Pandsh Pandsh -4 years ago 118
R Question

I want to print start time, end time and total execution in R, and append a label to it

old <- Sys.time()


// MY code

new <- Sys.time()


total time = old-new
the output comes "Time difference of -6.661923 secs"

instead i want "Execution time : 0.35secs"

Answer Source

You can use sprintf as below:

old <- Sys.time()
rnorm(500,0,1)
new <- Sys.time()
x <- (new - old)

sprintf("The execution time is %5.2f secs",x)

Output:

[1] "The execution time is  1.08 secs"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download