Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 211988

How can we build a timer for 5 different player using closure in R

$
0
0

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


Viewing all articles
Browse latest Browse all 211988

Trending Articles