[R-pkg-devel] Weird error on CRAN linux check
David Hugh-Jones
d@vidhughjone@ @ending from gm@il@com
Thu Jul 5 11:22:19 CEST 2018
Wow, this is extremely helpful. I've applied Joris' patch. By the way, the
github master has the change that I stopped exporting methods, as per
Hadley's suggestion; this caused *all* functions created via
make_getter_setters to fail. Version 4.0.1 on CRAN has the methods
exported, which was masking the error in most cases. I don't know why
bold() was failing in certain cases only... in any case, the patch seems to
fix things.
Here is a brief test case that shows the original problem. I don't know
whether this reveals any problem in base R:
# in package mypackage:
#' @export
foo <- function (x, ...) UseMethod('foo')
make_a_method <- function () assign("foo.bar", function (x, ...) cat("In
foo.bar"), pos = getNamespace('mypackage'))
make_a_method()
# in the console:
library(mypackage)
mypackage:::foo.bar
## function (x, ...) cat("In foo.bar")
## <bytecode: 0x109a0ab80>
## <environment: 0x109a0ba28>
x <- structure(1, class='bar')
foo(x)
## Error in UseMethod("foo") :
## no applicable method for 'foo' applied to an object of class "bar"
Also, I know I shouldn't be using @s3method ... it's on the TODO list... !
Cheers,
David
On Thu, 5 Jul 2018 at 09:07, Iñaki Úcar <i.ucar86 using gmail.com> wrote:
> El mié., 4 jul. 2018 a las 22:47, Duncan Murdoch
> (<murdoch.duncan using gmail.com>) escribió:
> >
> > On 04/07/2018 4:04 PM, Joris Meys wrote:
> > >
> > >
> > > On Wed, Jul 4, 2018 at 9:31 PM, Duncan Murdoch <
> murdoch.duncan using gmail.com
> > > <mailto:murdoch.duncan using gmail.com>> wrote:
> > >
> > >
> > > That shouldn't matter. That function was created in a local
> > > environment whose parent is <environment: namespace:huxtable>
> > > (probably by the huxtable:::make_setter_getters function, but I
> > > didn't check).
> > >
> > > Duncan Murdoch
> > >
> > > I would think it does matter. Methods are found on the search path, but
> > > the environment where the methods are defined is not on the search
> path.
> > > It's a child environment of the namespace, and hence cannot be reached
> > > from either the global environment or the namespace if I understood it
> > > correctly.
> > >
> >
> > The environment of a function is where it looks for objects, not where
> > it is stored. That method is stored in the huxtable namespace, and
> > exported from it. That's why
> > getFromNamespace("align.huxtable","huxtable") (or even
> > huxtable::align.huxtable) finds it.
> >
> > I don't know the source of the original error.
>
> I don't know either. But obviously it has something to do with the
> function environment and how UseMethod looks for methods when they are
> exported from a namespace (I tested a similar "layout" in the global
> environment and the method is correctly found). So maybe this thread
> belongs to r-devel instead.
>
> Iñaki
>
> >
> > Duncan Murdoch
> >
>
> ______________________________________________
> R-package-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>
[[alternative HTML version deleted]]
More information about the R-package-devel
mailing list