CRAN提交失败-警告:未找到与“show”的方法导出对应的函数

jaxagkaj  于 2023-11-14  发布在  其他
关注(0)|答案(1)|浏览(96)

我最近向CRAN提交了我的R package,在检查过程中我遇到了一个注解。注解看起来像这样:

Check: whether the namespace can be loaded with stated dependencies, Result: NOTE
  Warning: no function found corresponding to methods exports from 'hmsr' for: 'show'

  A namespace must be able to be loaded with just the base namespace
  loaded: otherwise if the namespace gets loaded by a saved object, the
  session will be unable to start.

  Probably some imports need to be declared in the NAMESPACE file.

字符串
我正在寻求帮助来理解和解决这个问题。
show是这样定义的:

#' Show method for class "hms".
#'
#' @param object - hms s4 object
#'
#' @return It returns the names of the slots and the classes associated with the
#' slots in the "hms" class. It prints call details.
#'
#' @export
#'
#' @examples
#' f <- function(x) x
#' result <- hms(fitness = f, lower = -5, upper = 5)
#' show(result)
setMethod("show", "hms", function(object) {
  cat("An object of class \"hms\"\n")
  cat("\nCall:\n", deparse(object@call), "\n\n", sep = "")
  cat("Available slots:\n")
  print(methods::slotNames(object))
})


在NAMESPACE中,有一行看起来像这样:

exportMethods(show)


我正在调查show是否定义正确,GA包是否有一个非常类似的show方法:

setMethod("show", "ga",
function(object)
 { cat("An object of class \"ga\"\n")
   cat("\nCall:\n", deparse(object@call), "\n\n",sep="")
   cat("Available slots:\n")
   print(slotNames(object))
})


我不能在我的个人电脑上用Windows复制这张纸条。在Mac OS上我从来没有经历过这张纸条。

6vl6ewon

6vl6ewon1#

我通过在setMethod("show"前面添加以下代码块来摆脱此警告消息

#' Show
#' @importFrom methods show
#' @inheritParams methods::show
#' @export
show <- methods::show

字符串
methods添加到DESCRIPTION文件的Imports:部分

相关问题