【问题标题】:R: Warning when building a packageR:构建包时的警告
【发布时间】:2015-12-08 23:43:52
【问题描述】:

在我正在编写的包中,我有一个用于类对象的“自定义”打印函数,例如“myclass”。

print.myclass <- { 
  # ... 
  # ...
}

在 print.myclass.Rd 文件中,我有这样的内容:

\name{print.myclass}
\alias{print.myclass}
\alias{print}
\title{Print method for objects of class \code{myclass}.}
\description{Display \code{myclass} objects in the console or in \emph{RStudio's Viewer}.}
\usage{
  \method{print}{myclass}(x, method, \dots)
  print(x, method="some.method", ...)
}

当我运行 R CMD check --as-cran 时,我收到以下警告:

* checking for code/documentation mismatches ... WARNING Functions or methods
with usage in documentation object 'print.summarytools' but not in code:   
print

我一定已经尝试了所有可能的试错组合,导入这个并删除那个,但我碰壁了。我什至不确定“但不在代码中”是什么意思......我们是在谈论 R 脚本中的 R 代码,还是 .Rd 文件中的代码?

我希望有足够经验的人能够指导我走向光明。

谢谢

【问题讨论】:

  • 是的,我读到 with usage in documentation ... but not in code 建议您已覆盖.Rd 方面,但.R 存在问题一边。
  • 取出\alias{print} ??我认为“但不在代码中”的意思是“但[相关函数未在包的 R] 代码中的任何地方定义”
  • 它建议我在你的 .Rd 文件的某个地方调用 print.summarytools 方法,但它没有在你的包中定义。据我所知,它不是base install 集合print 方法的一部分,所以 cran-checker 找不到它。
  • 试图删除\alias{print} 产生了一个新的警告(哦,我多么喜欢tose)实际上导致我成为罪魁祸首。 Objects in \usage without \alias in documentation object [...]。所以我回到了我的\usage 部分;它的第二行是罪魁祸首。因此,“code”显然是指 \usage 部分。谢谢你们的帮助。

标签: r package


【解决方案1】:

解决办法就是去掉\usage部分的第二行:

\usage{
  \method{print}{myclass}(x, method, \dots)
  print(x, method="some.method", ...)        <- culprit
}

为了保留第二行中给出的附加信息(method 的默认值,这样可以:

\usage{
  \method{print}{myclass}(x, method="some.method", \dots)
}

【讨论】:

    猜你喜欢
    • 2012-08-11
    • 2013-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多