[Rd] odd assignInNamespace / setGeneric interaction

Michael Lawrence lawrence.michael at gene.com
Wed Apr 18 23:16:37 CEST 2018


Hi Bill,

Ideally, your coworker would just make an alias (or shortcut or
whatever) for R that passed --no-save to R. I'll try to look into this
though.

Michael

On Wed, Apr 18, 2018 at 1:38 PM, William Dunlap via R-devel
<r-devel at r-project.org> wrote:
> A coworker got tired of having to type 'yes' or 'no' after quitting R: he
> never wanted to save the R workspace when quitting.  So he added
> assignInNamespace lines to his .Rprofile file to replace base::q with
> one that, by default, called the original with save="no"..
>
>   utils::assignInNamespace(".qOrig", base::q, "base")
>   utils::assignInNamespace("q", function(save = "no", ...)
> base:::.qOrig(save = save, ...), "base")
>
> This worked fine until he decide to load the distr package:
>
>   > suppressPackageStartupMessages(library(distr))
>   Error: package or namespace load failed for ‘distr’ in
> loadNamespace(name):
>    there is no package called ‘.GlobalEnv’
>
> distr calls setGeneric("q"), which indirectly causes the environment
> of base::q, .GlobalEnv, to be loaded as a namespace, causing the error.
> Giving his replacement q function the environment getNamespace("base")
> avoids the problem.
>
> I can reproduce the problem by making a package that just calls
> setGeneric("as.hexmode",...) and a NAMEPACE file with
> exportMethods("as.hexmode").  If my .Rprofile puts a version of as.hexmode
> with environment .GlobalEnv into the base namespace, then I get the same
> error when trying to load the package.
>
> I suppose this is mostly a curiosity and unlikely to happen to most people
> but it did confuse us for a while.
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



More information about the R-devel mailing list