如何在Package中扩展Package的引用类?

时间:2014-08-13 16:13:36

标签: r package reference-class

问题

下图显示了我的问题:

enter image description here

我正在尝试在ClassB中创建引用类PackageB,该引用类将引用类ClassA扩展到另一个包PackageA中。

一旦ClassB被实例化,R就会抱怨PackageA的私有(非导出)对象(特别是函数)无法找到。

最小工作示例(MWE)

下图显示了MWE的工作原理:

enter image description here

ClassA取决于PackageA中的2个私有函数(来自fractions的{​​{1}} - ed package import,以及MASS定义的PrivateFunc 1}}本身)。 PackageA隐含地依赖于这些函数,通过它继承ClassB

一旦ClassA被实例化,就会出现错误,抱怨无法找到ClassB。构建PrivateFunc时会出现这些错误。

代码:

PackageB

我尝试构建########################################## # PackageA ### R/PackageA.R ### #' @import methods MASS PrivateFunc <- function(...) fractions(0.5) # try a function from MASS #' @export ClassA #' @exportClass ClassA ClassA <- setRefClass("ClassA", methods = list( initialize = function(...) PrivateFunc() ) ) ### DESCRIPTION: ### Package: PackageA ... Imports: methods, MASS ### NAMESPACE: ### # Generated by roxygen2 (4.0.1): do not edit by hand export(ClassA) exportClasses(ClassA) import(MASS) import(methods) ########################################## # PackageB ### R/PackageB.R ### #' @import methods PackageA #' @export ClassB #' @exportClass ClassB ClassB <- setRefClass("ClassB", contains = "ClassA") #' @export ClassBInstance ClassBInstance <- ClassB() # <- Error here!! ### DESCRIPTION: ### Package: PackageB ... Imports: methods, PackageA ### NAMESPACE: ### # Generated by roxygen2 (4.0.1): do not edit by hand export(ClassB) exportClasses(ClassB) export(ClassBInstance) import(PackageA) 时的错误:

PackageB

出了什么问题?

其他信息

==> devtools::document(roclets=c('rd', 'collate', 'namespace'))

Updating PackageB documentation
Loading PackageB
Error in .Object$initialize(...) : could not find function "PrivateFunc"
Error: Failure in roxygen block beginning PackageB.R:2
using 'as.environment(NULL)' is defunct
Execution halted

Exited with status 1.


==> Rcmd.exe INSTALL --no-multiarch --with-keep.source PackageB

* installing to library .../R/R-3.1.0/library'
* installing *source* package 'PackageB' ...
** R
** preparing package for lazy loading
Error in .Object$initialize(...) : could not find function "PrivateFunc"
Error : unable to load R code in package 'PackageB'
ERROR: lazy loading failed for package 'PackageB'
* removing '.../R/R-3.1.0/library/PackageB'
* restoring previous '.../R/R-3.1.0/library/PackageB'

Exited with status 1.

0 个答案:

没有答案