1

The question at hand is how to, within an R package, call and use a function with a dependency.

For example, I have written a function that uses the nFactors::parallel function. This function makes a call to MASS::mvrnorm, but when I run my function: function() I get the following error: Error: could not find function "mvrnorm"

In my DESCRIPTION file I have (I am using roxygen2):

Imports:
    MASS,
    nFactors

and in my function.R file I have tried including:

#' @import MASS
#' @import nFactors

as well as:

#' @importFrom MASS mvrnorm 
#' @importFrom nFactors parallel

to no avail.

If I call library(MASS) in the first line of my function, the problem is alleviated, but this loads the entire MASS package for the user which isn't desired.

Thank you for any insight.

EDIT: This isn't simply a question of 'how can I utilize a particular function without importing the entire namespace'. This is more of a question of nested imports.

mc-sq
  • 169
  • 1
  • 9
  • Possible duplicate of [How to import only one function from another package, without loading the entire namespace](http://stackoverflow.com/questions/19838360/how-to-import-only-one-function-from-another-package-without-loading-the-entire) – Pdubbs Mar 30 '17 at 16:18
  • @Pdubbs I disagree. This is a different question. They don't say they have an issue with loading all of nFactors (or even all of MASS!). It's that the function they want to use isn't working when imported. – Dason Mar 30 '17 at 16:19
  • I don't know if there is a better solution but putting nFactors in Depends instead of Imports should fix your issue. – Dason Mar 30 '17 at 16:20
  • I agree, @Dason, the question at hand is not the same - I tried to make that more clear in the text body. Either way, thank you, adding to Depends fixes the problem at hand. I will explore more. – mc-sq Mar 30 '17 at 16:31
  • It's an issue with using Depends and how NAMESPACE works. Ideally the nFactors package would update to using Imports instead of Depends and if/when that happens then you could just import as well and things would work out just fine. – Dason Mar 30 '17 at 16:42
  • @Dason you're right, I wasn't reading closely enough. My apologies. – Pdubbs Mar 30 '17 at 19:53

0 Answers0