【问题标题】:Roxygen2 unable to find class definition during build & checkRoxygen2 在构建和检查期间无法找到类定义
【发布时间】:2017-07-20 18:11:43
【问题描述】:

我在使用 devtool 的 build() 和 check() 函数构建 R 包时遇到了许多问题。最严重的是这些函数在R目录下的.R文件中找不到用setClass创建的类定义。

例如,以下代码包含在 R\rnet.input.R 中,并定义了一个对象,该对象包含从它继承的更涉及的类的各种插槽。

#' rnet.input - An S4 class for accepting input data common for generating all rnet objects. These objects are used to handle rnet objects and need not be called by the user.
#' 
#' The superclass for holding input for rnet functions.
#' 
#' @slot RawData A dataframe containing the original dataset.
#' @slot cor_method The type of correlation matrix to use. Must be a partial match to one of the following strings: 'pearson', 'spearman', 'kendall'.
#' @slot cor_pairing Method for handling how missing data is handled in pairs. See 'pair' argument in function 'cor' for more information.
#' @slot n_threshold The minimum number of valid pair-wise observations that must exist for an edge to be estimated. Vertex pairs with fewer valid pair-wise observations are assumed to be conditiontally independent.
#' @slot L1_orig The declared L1 penalty to be used when estimating rnet topology
#' @slot v_set_orig The declared set of k variables to be included in the rnet as vertices
#' @slot Forced_zeros A matrix with 2 columns containing pairs of vertices to force to be conditionally independent in the rnet
#' @slot Layout_master A k x 2 matrix x & y coordinates of each vertex in the graph.

rnet.input <- setClass(Class = "rnet.input",
                   slots = list(
                     RawData = 'data.frame',
                     cor_method = 'character',
                     cor_pairing = 'character',
                     n_threshold = 'numeric',
                     L1_orig = 'numeric',
                     V_set_orig = 'character',
                     Forced_zeros = 'matrix',
                     Layout_master = 'ANY'
                   )
)

但是,在 build() 和 check() 期间,由于以下错误,该过程失败:

Error in reconcilePropertiesAndPrototype(name, slots, prototype, superClasses,  :no definition was found for superclass “rnet.input” in the specification of class “rnet.basic”

我尝试将 .R 文件放置在多个位置定义这些类的位置。唯一发生变化的情况是当我在一个文件中拥有所有 5 个定义时,此时检查将运行,但仍声称它们在某些时候未定义并且存在“sodoc”冲突。我也尝试过添加名称、rdname、export 和 exportClass 标签,但这并没有解决任何问题。

其他问题包括 check() 声称具有文档的数据集未记录,并且其他数据集在多个位置创建,即使对这些对象的代码引用仅在单个文件中出现一次。

感谢任何帮助。

【问题讨论】:

  • 这是我们可以 fork 的 GitHub 上的仓库吗?
  • 是的,谢谢,我打算包括在内。它可用here。我认为我用来构建包的代码也在那里。如果不是,我会添加它。我对使用 github 也很陌生,如果存储库一团糟,敬请见谅。

标签: r devtools roxygen2 r-package


【解决方案1】:

好的,这很容易。

您需要添加#' @include Rnet_classes.R,例如在setGeneric('Assign_Emetadata' 的文档中,以便roxygen2 知道它应该在之前渲染。

这将在您的说明文件中添加一个Collate: 字段。

【讨论】:

  • 谢谢,我试过这个并将更新代码提交/推送(?)到存储库。仅对 Assign_Emetadata 文件进行了更改。构建仍然失败,现在抛出错误:Error in .install_package_code_files(".", instdir) : files in 'Collate' field missing from 'C:/Users/Will/AppData/Local/Temp/Rtmp6lAj0D/Rbuilda6438447191/Rnets/R': Rnet_classes ERROR: unable to collate and parse R files for package 'Rnets'
  • 跟进在谷歌上搜索“无法整理和解析”错误后,似乎表明存在左括号或其他错误,阻止文件中的代码在没有的情况下运行错误。 Duncan Murdoch 对该主题的回应建议在每个文件上检查 parse(),另一个建议在每个文件上尝试 source()。包中的代码通过了这个测试,有两个例外: 1 - 大型数据集失败 2 - 'igraph' 是一个 S3 类,所以它只是一个列表。我修复了这些(1 通过删除数据,2 通过更改签名),并且“无法解析”错误仍然存​​在。
  • 已解决我发现了错误。我在一个我认为我没有修改过的文件中添加了#' @include Rnet_classes,但没有'.R'。它现在构建,几乎没有错误。再次感谢你的帮助。我决定留下以前的 cmets,以防他们帮助别人。
猜你喜欢
  • 2010-11-20
  • 1970-01-01
  • 1970-01-01
  • 2012-12-13
  • 1970-01-01
  • 2016-07-06
  • 1970-01-01
  • 1970-01-01
  • 2011-08-05
相关资源
最近更新 更多