Skip to content

Instantly share code, notes, and snippets.

@jumpingrivers jumpingrivers/clock.R
Last active Jun 20, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.