There are 4 separate function for starting, ending, get their duration and display their result in desc order which needs to be implemented using closure. I was trying to implement three functions first :-
StopWatch <- function(){
list(strt<-function(Name = "name") Start <<- Sys.time(),
stop<-function() End <<- Sys.time(),
duration<-function(){ t <<- Start- End
print(t)})
}
w<- StopWatch()
w$strt("player1")
sleep_for_a_minute()
w$stop()
w$duration()
When I run w$strt("player1") it give an Error: attempt to apply non-function