I am a bit confused about this. I have an R package that has a small function (not a mayor part of the package) in which the principal
function of the psych
package is called. How do I correctly specify this in DESCRIPTION and NAMESPACE?
Setting Depends: psych
in DESCRIPTION makes sure the psych package is loaded every time my package is loaded. This works, but it seems redundant for such a small part of my package.
Setting Suggests: psych
and entering a require("psych")
in the function is what I do now, however this does not work if psych
is not installed, and seems to be the wrong way of doing this (writing R extensions says that suggest is meant mainly for examples).
I think I need to import the function. I tried setting Imports: psych
in DESCRIPTION and importFrom(psych,"principal")
in NAMESPACE. This works, but on a computer that does not has psych installed it gives an error when loading my package.
The basic question you need to answer is: "do you want the function to be available to all users of the package without further effort?". If yes, then use imports + the appropriate namespace declarations, if no, then use suggests and print an informative error message if
require("psych")
returnsFALSE
.I don't understand your import related complaint that: "but on a computer that does not has psych installed it gives an error when loading my package". This is also true if your package is in depends!