If you're interested in using GRASS for this, here are the steps. To smooth the original, r.neighbors creates a new raster where each pixel gets the average value of surrounding pixels within a window. THen you can use r.recode to get a new raster with discrete categorical values replacing the continous population density. And finally, r.to.vect will convert ...
Note where the error is coming from and step through your code. Its not even getting to the Savitsky-Golay line.
> v = as.vector(r)
> z = na.spline(v)
> s1.ts2 = ts(z, start=1, end=nlayers(z), frequency=12)
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘nlayers’ for signature ‘"numeric"’
The error ...