open-close intraday demeaned log return calculation

open-close return is basically what I feed into the realized kernel volatility and recently I noticed the realized kernel covariance/variance is generating negative value so I had to retrace my calculation to the very begining and I became increasingly unsure about my calculation, though it may well be the wrong culprit.

Here's the traditional log return formulae: $$\text{ } R_t = log (\frac{p_{close}}{p_{open}}) = log(p_{close}) - log(p_{open})$$

and to demean it: $$\text{ } R_{demean} = R_t - {\mathbb{E}}[R_t]$$

The relevant R code goes:

oc.logret <- function(open, close){
oc.lret <- log(close) - log(open)
oc.lret.demeaned <- oc.lret - mean(oc.lret)
}


Is this calculation for open-close demeaned log return incorrect?