[Rd] S3 weirdness

Gabor Grothendieck ggrothend|eck @end|ng |rom gm@||@com
Fri Jun 25 01:47:35 CEST 2021


The fact that zoo:: in one part of the code has a side effect in
another seems not to be in the spirit of functional programming or
modularity.

On Thu, Jun 24, 2021 at 6:51 PM Simon Urbanek
<simon.urbanek using r-project.org> wrote:
>
> Gabor,
>
> just by using zoo::read.zoo() you *do* load the namespace:
>
> > args(zoo::read.zoo)
> function (file, format = "", tz = "", FUN = NULL, regular = FALSE,
>     index.column = 1, drop = TRUE, FUN2 = NULL, split = NULL,
>     aggregate = FALSE, ..., text, read = read.table)
> NULL
> > sessionInfo()
> R Under development (unstable) (2021-06-23 r80548)
> Platform: x86_64-apple-darwin19.6.0 (64-bit)
> Running under: macOS Catalina 10.15.7
>
> Matrix products: default
> BLAS:   /Volumes/Builds/R/build/lib/libRblas.dylib
> LAPACK: /Volumes/Builds/R/build/lib/libRlapack.dylib
>
> locale:
> [1] en_NZ.UTF-8/en_NZ.UTF-8/en_NZ.UTF-8/C/en_NZ.UTF-8/en_NZ.UTF-8
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> loaded via a namespace (and not attached):
> [1] zoo_1.8-9       compiler_4.2.0  grid_4.2.0      lattice_0.20-44
>
> which includes S3 method dispatch tables:
>
> > methods(as.ts)
> [1] as.ts.default* as.ts.zoo*     as.ts.zooreg*
> see '?methods' for accessing help and source code
>
> so the behavior is as expected.
>
> Cheers,
> Simon
>
>
> > On 25/06/2021, at 9:56 AM, Gabor Grothendieck <ggrothendieck using gmail.com> wrote:
> >
> > If we start up a vanilla session of R with no packages loaded and
> > type the single line of code below as the first line entered then
> > we get the output shown below.  The NA in the output and the length
> > of 7 indicate that as.ts dispatched as.ts.zoo since as.ts.default
> > would have resulted in a length of 6 with no NA's. It should not have
> > known about as.ts.zoo since we never  explicitly loaded the zoo
> > package using library or require.
> > zoo:: was only used to refer to read.zoo.  This seems to be a bug in
> > the way R is currently working.
> >
> >  as.ts(zoo::read.zoo(BOD))
> >  ## Time Series:
> >  ## Start = 1
> >  ## End = 7
> >  ## Frequency = 1
> >  ## [1]  8.3 10.3 19.0 16.0 15.6   NA 19.8
> >
> >  R.version.string
> >  ## [1] "R version 4.1.0 RC (2021-05-16 r80303)"
> >
> > --
> > Statistics & Software Consulting
> > GKX Group, GKX Associates Inc.
> > tel: 1-877-GKX-GROUP
> > email: ggrothendieck at gmail.com
> >
> > ______________________________________________
> > R-devel using r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
> >
>


-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-devel mailing list