[Rd] S3 weirdness

Johannes Rauh JAR@uh @end|ng |rom web@de
Fri Jun 25 09:16:20 CEST 2021


Good morning,

I would argue that in this specific simple example, R does the less confusing thing from a user's perspective (maybe not from a programmer's or philosopher's perspective):

When using a function from a package that has not been loaded before and when this package creates an object of a "new" class that has not been seen before, R makes sure that its object system from now on recognizes this class.

Cheers
Johannes

> Gesendet: Freitag, 25. Juni 2021 um 08:32 Uhr
> Von: "Gabriel Becker" <gabembecker using gmail.com>
> An: "Gabor Grothendieck" <ggrothendieck using gmail.com>
> Cc: "Simon Urbanek" <simon.urbanek using r-project.org>, "r-devel using r-project.org" <r-devel using r-project.org>
> Betreff: Re: [Rd] S3 weirdness
>
> On Thu, Jun 24, 2021 at 4:48 PM Gabor Grothendieck <ggrothendieck using gmail.com>
> wrote:
>
> > 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.
> >
>
> While this is true, there is no way I know of for a package function
> to...well, function in the general case without its namespace loaded, and
> as has been brought up many times on this list, unloading namespaces fully
> also doesn't work in the fully general case. Given those facts, it seems
> the current behavior is essentially all that is possible to be done, right?
>
> Also even if a namespace could be unloaded, can you imagine the penalty if
> the namespace was loaded and then unloaded after every :: call? Some
> scripts would just never complete at all. I kid, of course, but not by that
> much I think...
>
> ~G
>
>
> >
> > 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
> >
> > ______________________________________________
> > R-devel using r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
> >
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



More information about the R-devel mailing list