[R] package zoo, function na.spline with option maxgap -> Error: attempt to apply non-function?

R. Michael Weylandt michael.weylandt at gmail.com
Wed Jun 6 22:10:14 CEST 2012


Thanks for the great reproducible example -- I can confirm on the
devel version of zoo.

I'd venture it's a buglet in that maxgap gets passed (by way of dots)
to na.spline --> na.spline.zoo --> na.spline.default --> na.spline.vec
--> to both .fill_short_gaps (good) and spline (bad) which is where
the error arises.

I'll wait for Gabor or Achim to officially weigh in though.

Michael

On Wed, Jun 6, 2012 at 2:55 PM, May Katharina
<may.katharina at googlemail.com> wrote:
> Hello,
>
> I'm trying to use na.spline (package zoo) to fill some missing data in a time series.
> this works fine, however, if I apply the 'maxgap' argument, I always get the error:
> <------
> Error in na.spline.vec(x., coredata(object.), xout = xout., ...) :  attempt to apply non-function
> ------>
>
> I couldn't find a similar error for this case in the mailing lists and zoo vignette, I hope I didn't
> miss any basic thing, but as I don't know how to proceed, any help on why this isn't working
> is very much appreciated  (I guess I don't have to mention I'm new to time series & zoo and that I'm terrible sorry if this is
> an absolute dull question).
>
> The data I use is rather large, but the error can be reconstructed in a small example (s. below).
> If of any interest: I use R 2.15.0 GUI 1.51 Leopard build 32-bit (6148).
>
> Many thanks and best regards, Katharina
>
>
> <------
> library(zoo)
>
> #create data + gaps
> z <- zoo(seq(1:30), seq(1900, length =30 ))
> z[c(2,5,6,7,9,10,15,16,17,20,21)] <- NA
>
>> z
> 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921
>   1   NA    3    4   NA   NA   NA    8   NA   NA   11   12   13   14   NA   NA   NA   18   19   NA   NA   22
> 1922 1923 1924 1925 1926 1927 1928 1929
>  23   24   25   26   27   28   29   30
>
> #1. fill using spline: this version without gap restriction works
>> na.spline(z)
> 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921
>   1    2    3    4    5    6    7    8    9   10   11   12   13   14   15   16   17   18   19   20   21   22
> 1922 1923 1924 1925 1926 1927 1928 1929
>  23   24   25   26   27   28   29   30
>
> #2. fill using spline: a=with applying 'maxgap' an error is produced
>> na.spline(z, maxgap=2)
> Error in na.spline.vec(x., coredata(object.), xout = xout., ...) :
>  attempt to apply non-function
> ------>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list