情节的新方法-如何导出? [英] New method for plot - how to export?

查看:66
本文介绍了情节的新方法-如何导出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个包装,在其中我想定义一种新的绘图方法.我正在使用roxygen的源文件.这个问题似乎非常类似于:如何使用Roxygen从不同的软件包中正确记录了通用的S3方法? Roxygen2-如何正确记录S3方法但我仍然无法使其正常工作.

I am making a package where I want to define a new method for plot. I am using roxygen in-source documentation. This question seems very similar to: How to properly document a S3 method of a generic from a different package, using Roxygen? and Roxygen2 - how to properly document S3 methods but I still cannot get it to work.

引起我麻烦的相关部分是:

The relevant parts that are causing me trouble are:

#' Generic plot method
#'
#' @param x \dots
#' @param ... \dots
#' @export
plot <- function(x, ...) UseMethod("plot")

#' Default plot method
#'
#' @param x \dots
#' @param ... \dots
#' @importFrom graphics plot
#' @method plot default
#' @S3method plot default
plot.default <- function(x, ...) graphics::plot(x, ...)

#' Plotting function for ABI object
#'
#' Description.
#' 
#' @param x ABI object as generated by newABI.
#' @param base Character. Bases to look at.
#' @param ... Other options passed to plot().
#' @return Nothing. Side-effect: plots graphs.
#' @method plot ABI
#' @S3method plot ABI
plot.ABI <- function(x, base, ...) {
#Overly simplified
plot(1, 1, main = base)
}

运行此命令并调查方法(图)时,没有为ABI对象定义方法.通过ABI ::: plot(ABI是程序包的名称)访问该功能确实可行.不使用::.

When I run this and investigate methods(plot), there is no method defined for ABI objects. Accessing the function by ABI:::plot (ABI is the name of the package) does work. Using :: does not.

在软件包构建检查期间,出现警告:

During the package build check, there is a warning:

* checking S3 generic/method consistency ... WARNING
plot:
  function(x)
plot.ABI:
  function(x, base, ...)
See section ‘Generic functions and methods’ of the ‘Writing R
Extensions’ manual.

似乎在争论上存在分歧.但是我不明白这一点,因为泛型具有参数x和...,而我的ABI方法(除了base)也有参数.

It seems that there is a disagreement in arguments. But I don't understand this, since the generic has arguments x and ... and so does my ABI method (in addition to base).

因此,有两个问题,我希望源于同一问题:plot.ABI方法未导出,并且程序包检查引发警告.

So there are two problems, which I hope stem from the same issue: The plot.ABI method is not exported and the package check throws a warning.

我该如何解决?

推荐答案

一些问题:

  1. 不包括已经在其他地方定义的泛型.只需添加您的方法即可.

  1. Don't include a generic that is already defined elsewhere. Just add your method.

每个方法的签名必须至少以相同的顺序包含泛型中的每个元素.有时很烦人,但毫无争议.

The signatures of every method must at least include every element in the generic, in the same order. It's annoying sometimes, but it's incontrovertible.

更新

我曾经说过,您的 @export 需要列出函数名称,"但显然这是不正确的.查看评论.还请注意,列出该方法应将其导出.我似乎还记得在您的包名称空间中未包含泛型的情况下,需要进行显式导出,但是我可能是错的(通常是这样!).

I had said, "Your @export needs to list the function name," but apparently this is not correct. See the comments. Note also that listing the method should export it. I seem to recall needing an explicit export in cases where you aren't including the generic in your package's namespace, but I could be wrong (so often am!).

这篇关于情节的新方法-如何导出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆