[R-pkg-devel] Should a package run without calling library?

Uwe Ligges ||gge@ @end|ng |rom @t@t|@t|k@tu-dortmund@de
Tue Sep 1 10:02:57 CEST 2020



On 01.09.2020 09:43, Richel Bilderbeek wrote:
> Dear fellow R package maintainers,
> 
> I would enjoy your advice to clarify a CRAN policy issue.
> 
> The question is: should a package be able to work, when calling its exported functions using the scope operator? Or, in the example code below, should #1 work?
> 
> 
> 
> ```
> # 1. Scope operator: should this always work?
> mypackage::myfunction()
> 
> # Possible error message:
> # Error in myfunction() :
> # object 'myhiddenfunction' of mode 'function' was not found

Yes.

> 
> # 2. Calling library first
> library(mypackage)
> myfunction()
> ```

Yes.


> I feel the answer is 'yes, #1 should work', as I feel this is only indirectly a CRAN repository policy [1] , the IMHO relevant one which I quote: 'Packages should not modify the global environment (user’s workspace).'. This means that if I have a function that calls `mypackage::myfunction`, it will call `library`:

No, it can import from the namespace, i.e. it loads the package, but 
does not modify the search path (i.e. does not attach the package).

Also note the workspace (=.GlobalEnv) is not the search path.

Best,
Uwe Ligges






> 
> ```
> #' Function in another package, that depends on my package
> do_something <- function() {
> library(mypackage)
> myfunction()
> }
> ```
> 
> So, should a package be able to work, when calling its exported functions using the scope operator?
> 
> Thanks for your advice/pointers, Richel Bilderbeek
> 
> 
> * [1] <https://mirror.las.iastate.edu/CRAN/web/packages/policies.html>
> 
> 
> 
> ______________________________________________
> 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