Savitzky-Golay Filters: time series using EVI

Hi all,
I am getting an error on a Savitzky-Golay Filters: Approximating Time Series using R while trying to execute Savitzky-Golay filter using a function from the signal package. I am attaching the code and the error it produces below.

fun <- function(x) {
v=as.vector(x)
z=substituteNA(v, type='mean')
EVI_RSM_stack.ts2 = ts(z, start=c(2018,05), end=c(2018,08), frequency=16)
x=sgolayfilt(EVI_RSM_stack.ts2, p=1, n=3, ts=30)
}

EVI_RSM_stack.filtered <- calc(EVI_RSM_stack, fun)

The error is
Error in .calcTest(x[1:5], fun, na.rm, forcefun, forceapply) :
cannot use this function