下图显示了我的问题:
我正在尝试在ClassB
中创建引用类PackageB
,该引用类将引用类ClassA
扩展到另一个包PackageA
中。
一旦ClassB
被实例化,R就会抱怨PackageA
的私有(非导出)对象(特别是函数)无法找到。
下图显示了MWE的工作原理:
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.