Nicholas Hamilton
Nicholas Hamilton

Reputation: 10506

R import all but a couple of functions

I am working on the upgrade to ggtern to handle ggplot 2.0.X, I need to import the grid package, however, ggplot2 is now exporting arrow and unit functions, which generates warnings when my package is loaded:

Warning messages:
1: replacing previous import by ‘grid::arrow’ when loading ‘ggtern’ 
2: replacing previous import by ‘grid::unit’ when loading ‘ggtern’ 

Is it possible to import the library with the exception of a couple of functions, ie something to the effect of the following might be useful in roxygen:

#' @importAllExcept grid arrow unit

Which should have the same effect as the following, (minus importing arrow and unit):

#' @import grid

Any suggestions?

Upvotes: 5

Views: 242

Answers (2)

Dan Chaltiel
Dan Chaltiel

Reputation: 8484

OK, this is a very late answer but I guess this still can help someone.

Since roxygen2 v5.0 (2015), you can use this syntax:

#' @rawNamespace import(grid, except=c(arrow, unit))

This will add the exact same text in NAMESPACE, which is exactly what you need.

Upvotes: 0

Roland
Roland

Reputation: 132676

Currently my best idea is

all <- getNamespaceExports("grid")
paste("@importFrom grid", paste(all[!(all %in% c("arrow", "unit"))], collapse = " ")) 
#[1] "@importFrom grid grid.edit pop.viewport ...

That's obviously not a good solution, but unlike for exports you can't use a regex for imports, i.e., there is no importPatternFrom.

Upvotes: 2

Related Questions