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

Richel Bilderbeek r|che| @end|ng |rom r|che|b||derbeek@n|
Tue Sep 1 09:43:17 CEST 2020


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


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

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`:


```
#' 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>





More information about the R-package-devel mailing list