Skip to content

Instantly share code, notes, and snippets.

@jumpingrivers
Last active June 20, 2018 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jumpingrivers/a8b4c8400cb718a53a0ddb2f01c5278d to your computer and use it in GitHub Desktop.
Save jumpingrivers/a8b4c8400cb718a53a0ddb2f01c5278d to your computer and use it in GitHub Desktop.
clock = function(max_laps=100) {
laps = numeric(max_laps)
laps[1] = Sys.time()
no_of_laps = 2
reset = function() {
no_of_laps = 1
laps <<- numeric(max_laps)
laps[no_of_laps] = Sys.time()
no_of_laps <<- 2
}
lap = function() {
laps[no_of_laps] <<- Sys.time()
no_of_laps <<- no_of_laps + 1
}
get_laps = function() {
laps[1:(no_of_laps-1)] - laps[1]
}
list(reset = reset,
lap = lap,
get_laps = get_laps)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment