I ran into following problem already multiple times.
Say you have two classes, classA
and classB
described in the following files classA.R
:
#' the class classA
#'
#' This is a class A blabla
#' \section{Slots}{\describe{\item{\code{A}}{a Character}}}
#' @ name classA
#' @rdname classA
#' @exportClass classA
setClass("classA",representation(A="character"))
And classB.R
#' the class classB
#'
#' This is a class B blabla
#' \section{Slots}{\describe{\item{\code{B}}{an object of class A}}}
#' @ name classB
#' @rdname classB
#' @exportClass classB
setClass("classB",representation(B="classA"))
I believed these files were read in alphabetical order by roxygen2
, but that is not the case. If I try to build the package, I might get the following error:
roxygenize("./myExample")
Error in getClass(Class, where = topenv(parent.frame())) :
"ClassA" is not a defined class
How can I make sure that roxygenize()
knows in which order to read the files, i.e. which class definition should be read before the other?
Note : I know I answered my own question. That is because I ran into this problem rather often, and realized the proper way to do this after looking at the code of roxygen2
. So for reference, here's my findings.