0

I want to run a code when sys.time() is specified.

I don't understand why if I write:

inputTime <- as.POSIXct("2018-02-21 14:51:00")

while(TRUE) {
  if(Sys.time() == inputTime){
    a <- 5
    b <- 6
    c <- a+b

    print(c)
  } 
}

I don't get any result, but if I write something like:

inputTime <- Sys.time()+3

while(TRUE) {
  if(Sys.time() == inputTime){
    a <- 5
    b <- 6

    c <- a+b

    print(c)
  } 
}

I get the result I was looking for (11 in this case).

Can you please help me?

matcava
  • 53
  • 8
  • Could it be because `as.POSIXct("2018-02-21 14:51:00")` is in the past and thus `Sys.time()` would never equal it going forward, whereas `Sys.time()+3` is, by definition, 3 seconds in the future? – ktdrv Feb 21 '18 at 21:09
  • Hi @ktdrv, the date I inserted was just an example. Of course I put a future date, but it seems that Sys.time() and the given date do not match... – matcava Feb 22 '18 at 08:19
  • Same thing if I write: for (i in 1:50){ (Sys.time() == inputTime) }. With inputTime <- whatever you want, nothing happens... I really don't understand why – matcava Feb 22 '18 at 08:54

0 Answers0