How do I extend the PackageA reference class in PackageB?
Problem
The diagram below shows my problem:
I am trying to create a reference class ClassB
in PackageB
that extends the reference class ClassA
in another package PackageA
.
Once ClassB
created, R complains that private (non-exported) objects (functions in particular) PackageA
cannot be found.
Minimum Working Example (MWE)
The diagram below shows how MWE works:
ClassA
depends on 2 private functions in PackageA
( fractions
from import
-ed package MASS
and PrivateFunc
defined in itself PackageA
). ClassB
implicitly also depends on these functions through its inheritance ClassA
.
Once ClassB
created, an error occurs that PrivateFunc
cannot be found. These errors occur when I am building PackageB
.
Code:
##########################################
# 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)
Errors when trying to create 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.
What will go wrong?
Additional Information
version
_
platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
status
major 3
minor 1.0
year 2014
month 04
day 10
svn rev 65387
language R
version.string R version 3.1.0 (2014-04-10)
nickname Spring Dance
source to share
No one has answered this question yet
Check out similar questions: