I'm trying to import a S3 method, predict
from another package pls
. I have a function which uses these predicted values. The problem is, when compiling the package:
Error : object 'predict' is not exported by 'namespace:pls'
I've put together this Gist as a minimal example which highlights my problem and contains the following R file:
#' Test function
#'
#' @importFrom pls predict
#'
#' @export
myfunc <- function(x){
stopifnot(class(x) == "mvr")
predict(x)*2
}
To summarise this as the original (below) is now out-dated and in places erroneous or misleading.
The proximal issue is that there is no function named
predict
in the pls package; there are some unexported S3 methods forpredict
but no suchpredict
. So you can't import this. Thepredict
generic lives in the stats package and you'll need to import from there as discussed below.Your package needs to have
Depends: pls
in theDESCRIPTION
in order for the correctpredict
method to be available to R. There's nothing in pls that you can specifically import.You also need to import the
predict
generic from the stats namespace, so addas that will import the generic in you packages namespace. You will also want to add
Imports: stats
to yourDESCRIPTION
file to indicate that you need the stats package; previously we didn't have to declare dependencies on the set of base packages shipped with R (i.e. the non-Recommended ones that ship with R).Original
The main issue here is the pls doesn't define a function/method
predict
. It provides several methods for thepredict
generic, but not the generic itself.You need to import the generic from the stats package, if you need it - I'm not sure you do as you aren't creating a function that needs or builds on the generic. At the minimum you'll need
though you may need/want to import the entire stats namespace - depends what your package does beyond the function your are currently working on.
The other issue is that
predict.mvr
is not exported from the pls namespaceAs such you can't just import it. Hence your package needs to have
Depends: pls
in theDESCRIPTION
in order for the correctpredict
method to be found.