Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are explicit roxygen import from base package needed?

Tags:

r

r-package

Concrete example:

In my package, one of my functions uses grep form the base package.

Should I explicitly import grep or would that just introduce useless dependencies? I mean, everyone already has the base package, right?

For the sake of illustration:

#' Group_by with regex based column selection
#' Similar to `group_by` but grouping columns are selected with a regex.
#' @importFrom dplyr group_by
#' @importFrom base grep
#' @export
group_at <- function(df, pattern)
  group_by_(df, .dots=grep(names(df), pattern=pattern, value=T))
like image 739
asachet Avatar asked Nov 30 '16 10:11

asachet


2 Answers

From the Writing R Extensions manual sec.1.1.3:

It makes no sense to declare a dependence on R without a version specification, nor on the package base: this is an R package and package base is always available.

like image 89
Hong Ooi Avatar answered Nov 09 '22 07:11

Hong Ooi


By deleting the following terms associated to the package base from NAMESPACE

  import(base)  , 
 importFrom(base,system.file)

and in the DESCRIPTION file, delete the following term.

 Imports: base  

Then the following error vanished:

 preparing package for lazy loading
Error in asNamespace(ns, base.OK = FALSE) : 
  operation not allowed on base namespace
ERROR: lazy loading failed for package 'aa'
like image 26
Jean Billie Avatar answered Nov 09 '22 07:11

Jean Billie