Is there a way to automatically import functions from packages while writing an R package?

Viewed 219

Say, I write a function for an R package where I use functions from another package:

do_something <- function(path, agg_factor = 2) {
   x <- raster::raster(path)
   x <- raster::aggregate(x, fact = agg_factor)
   return(x)
}

I can easily import the raster and aggregate functions to the namespace by using roxygen2:

#' @importFrom raster raster aggregate

If I have a long function, I can even find which functions I should import by running R CMD CHECK in Rstudio/testthat but is there a way to automatically add these functions into the @importFrom field or equivalent field that automatically adds them when :: is used?

This would save a lot of time while writing large packages...

EDIT: as pointed out by @r2evans, @akrun, @user2554330 (see the comments), this was a stupid question. You need to do either :: or @importFrom but not both. See, for example, here. I will not delete the question since it provoked so much discussion. The moderators may if they want. It should probably be closed anyhow or someone can answer it clarifying my misunderstanding.

0 Answers
Related