[R-pkg-devel] failing S3 dispatch

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Wed Oct 20 11:02:41 CEST 2021


On 19/10/2021 3:43 p.m., Jens Oehlschlägel wrote:
> I didn't find an answer elsewhere:
> 
> My package 'bit' creates a S3 generic 'clone' and exports it.
> Furthermore it registers a S3 method 'clone.default' (not exported).
> 
> My package 'ff' imports package 'bit' and exports and registers a new S3
> method 'clone.ff'. However, calling 'clone(ffobj)' dispatches to
> clone.default instead of clone.ff !? Why?

You should show us the NAMESPACE entries involving clone and clone.ff 
from ff.

Some comments that may or may not be relevant:

  - Normally you wouldn't export clone.ff, it's enough to register it 
using S3method().

  - You may have created a new generic named clone, and that's what 
clone.ff would attach itself to.  You can have bit::clone and ff::clone 
as different generics and that would cause problems.

> 
> What is the recommended way to create new S3-methods that get
> dispatched? In earlier versions of the packages I simply exported
> everything - that worked.

I import the generic and use S3method(generic, method).  I don't export 
the methods, so I wouldn't be able to call z <- clone.ff(a).

Duncan Murdoch

> 
> Best
> 
> 
> Jens
> 
> 
>   > require(ff)
>   >
>   > a <- as.ff(0:9)
>   > class(x)
> [1] "ff_vector" "ff"
>   >
>   > x <- clone(a)
>   > y <- bit:::clone.default(a)
>   > z <- clone.ff(a)
>   >
>   > # cloned ffobjects should have different filenames>
> 
>   > filename(a)  # original
> [1] "/tmp/Rtmpk17JRZ/ff/clone1ed54cbb5060.ff"
>   >
>   > filename(x)  # unexpected equal (dispatch to clone.default)
> [1] "/tmp/Rtmpk17JRZ/ff/clone1ed54cbb5060.ff"
>   >
>   > filename(y)  # expected equal
> [1] "/tmp/Rtmpk17JRZ/ff/clone1ed54cbb5060.ff"
>   >
>   > filename(z)  # OK
> [1] "/tmp/Rtmpk17JRZ/ff/clone1ed551d3ee66.ff"
> 
>   > version
>                  _
> platform       x86_64-pc-linux-gnu
> arch           x86_64
> os             linux-gnu
> system         x86_64, linux-gnu
> status
> major          4
> minor          1.1
> year           2021
> month          08
> day            10
> svn rev        80725
> language       R
> version.string R version 4.1.1 (2021-08-10)
> nickname       Kick Things
> 
> ______________________________________________
> R-package-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>



More information about the R-package-devel mailing list