I have seen many questions on SO with this problem , but I can't understand , and relate to those with my case. I need to test for a case and then take appropriate action. Clearly the following code is not what I would eventually use ... but it illustrates the problem.
Code
Init Code
threshold <- 10
slotDuration <- 10 # data arriving in slotDuration sec will get into a single slot
totalSlots <- 200 # number of slots to keep
prevSlot <- 0
window <- slotDuration * totalSlots # window [time in sec] of data to cover
data <- array (0, dim=c(1,totalSlots))
handler <- function(transactionTime, dataValue){
# This line perhaps does not matter as the test uses the destSlot variable below.
dput(transactionTime)
n <- as.numeric(transactionTime, units = "secs")
# This is the var that causes problem
destSlot <- ceiling((n %% window)/slotDuration)
# this line should ensure we dont proceed on null values .. right ?
if (is.null(destSlot)) {
print("This is NULLL")
return (0)
}
if (!is.null(destSlot)) {
print(destSlot) ## prints numeric(0)
print("This is NOT NULLL")
}
if (destSlot != 0){ ## This line causes argument length zero error
prevSlot <<- destSlot
data[destSlot] <<- 0
}
data[destSlot] <<- data[destSlot] + dataValue
}
Output
structure(1475591155, class = c("POSIXct", "POSIXt"))
[1] 116
[1] "This is NOT NULLL"
Error in eval(substitute(expr), envir, enclos) :
argument is of length zero