Skip to content

Instantly share code, notes, and snippets.

@rmflight
Created August 15, 2012 17:58
Show Gist options
  • Save rmflight/3361972 to your computer and use it in GitHub Desktop.
Save rmflight/3361972 to your computer and use it in GitHub Desktop.
working with difftime objects in knitr

If you want to display time elapsed nicely in an Rmd object generated by knitr, here is my suggesion:

t1 <- Sys.time()
Sys.sleep(5)
t2 <- Sys.time()
tDiff <- difftime(t2, t1, units = "hours")

This process took 0.00139 hours. Note that units above can be whatever unit you want, see ?difftime.

If you want to display time elapsed nicely in an Rmd object generated by knitr, here is my suggesion:
```{r diffT}
t1 <- Sys.time()
Sys.sleep(5)
t2 <- Sys.time()
tDiff <- difftime(t2, t1, units="hours")
```
This process took `r format(tDiff)`. Note that units above can be whatever unit you want, see ?difftime.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment