old <- Sys.time()
// MY code
new <- Sys.time()
total time = old-new the output shows "Time difference -6.661923 sec"
instead I want "Runtime: 0.35 sec"
You can use sprintf as below:
sprintf
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"
Something like
old <- Sys.time() #code new <- Sys.time() total_time <- paste0("Execution time: ", as.numeric(new-old), "secs")