Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

Another package is removing my S4 'predict' method from the autocompletion candidates

$
0
0

I'm writing an R package where I implement my own 'predict' generic and an S4 method for the signature 'apk', which is an S4 class inside my package as well. I'm using Rstudio as editor and generating the documentation with Roxygen2.

All the problem goes about the autocompletion candidates that Rstudio shows when I type predict once the package is installed and loaded. Just after opening a new R session, if I type predict, I get the following candidates: predict {aPack}, predict {stats}, predict.glm {stats} and predict.lm {stats}. Note that both, the S4 from my package aPack and the one from stats are displayed as candidates. This happens because right before setting the generic, I imported predict from stats as suggested in this SO answer.

The problem: when I load another package with an S4 predict method, I'm no longer able to make my S4 show as autocomplete candidate. For instance, if I load the DiceKriging package and mine in the same session I only get the following candidates: predict {DiceKriging}, predict {stats}, predict.glm {stats}, predict.lm {stats} and predict.km {DiceKriging}. Once I load DiceKriging it is not possible to get my S4 displayed in autocomplete even if I load my package again. The predict method still works without predict {aPack} being listed by the autocompletion system, however, I would like to make it visible so that the user gets directly aware of the availability of my method.

Question: how sould I modify my roxygen documentation so that predict {aPack} gets prompted by the autocompletion system even if I load another package with a predict S4 method?

Minimal reproducible example

#' @title Class: apk model
#' @description To create an apk object, use \link[aPack]{apk}.
#' @slot call Object of class \code{"language"}. User call reminder.
#' @rdname apk-class
#' @import methods
#' @export
setClass("apk", representation(call = "language"), validity = function(object) {T})

#' @title Create an Object of class \code{"apk"}
#' @description Creator function for objects of class \code{"apk"}.
#' @param foo Not used yet.
#' @param ... Not used yet.
#' @export
apk <- function(foo, ...) {
    new("apk")
}

#' @name predict
#' @rdname predict-methods
#' @importFrom stats predict
#' @param object An object to predict from.
#' @param ... Further arguments for methods.
#' @export predict
setGeneric(name = "predict", def = function(object, ...) standardGeneric("predict"))

predict.apk <- function(object, bar,  ...) {
  print("I'm an apk prediction!")
}

#' @title Prediction Method for the apk Class
#' @name predict
#' @rdname predict-methods
#' @aliases predict,apk-method
#' @examples
#' myApk <- apk()
#' predict(myApk)
setMethod("predict", "apk", predict.apk)

GitHub: I also uploaded the project to GitHub so that you can directly make your suggested changes there if you want. The repository is here.


Viewing all articles
Browse latest Browse all 201867

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>