'R R6 Inheritance with roxygen2 - class "ParentClass" is not exported by 'namespace:ParentPackage'

I am running into an issue with R6 inheritance. I am writing 2 packages (work related so I have to use fake code but I'll try to keep it accurate).

In ParentPackage, I define an R6 class ParentClass.

#' @name ParentClass      
#' @title ParentClass 
#' @description blah blah
#' @importFrom R6 R6Class
#' @exportClass ParentClass 
#' @export
ParentClass <-
  R6Class('ParentClass',
     initialize() = function(){print('initialize')},
     list(method1 = function(){
      print('test') 
      }

# create helper function to create R6 class
#' @name create_ParentClass_object
#' @title Create a ParentClass object
#' @description
#' Helper function to create ParentClass object
#' @export create_ParentClass_object
create_ParentClass_object = function(){
  return(ParentClass$new())
}

Running the following after to install.

devtools::check()
roxygenize()
document()
install()

The NAMESPACE file looks correct.

export(ParentClass)
export(create_ParentClass_object)
exportClasses(ParentClass)
importFrom(R6,R6Class)

On to file 2, saved in a separate directory. It is called ChildPackage.

#' @name ChildClass
#' @title Create ChildClass Object
#' @description blah blah 2
#' @importFrom R6 R6Class
#' @importClassesFrom ParentPackage ParentClass
#' @importFrom ParentPackage ParentClass
#' @export
ChildClass<-
  R6Class('ChildClass',
          inherit = ParentClass,
          initialize = function(){},
          method2 = function(){}
)

But I get an error when trying to compile things.

roxygenise()
Warning message:
class "ParentClass" is not exported by 'namespace:ParentPackage' 
install()
Error: class "ParentClass" is not exported by 'namespace:ParentPackage' 

Note that loading the parent library shows the class. I.e., ParentPackage::ParentClass shows the class.

R version 4.0.3 (2020-10-10)
roxygen2_7.1.1        devtools_2.3.2        usethis_2.0.0   


Solution 1:[1]

I ran into similar errors when I forgot to add NULL after some general directives (like @import or @importClassesFrom). If you don't do that it adds the next commented lines to your directive. E.g.:

#' @importClassesFrom mydependency niceclass

#' Some other docs

Will return the following error while building:

Error: class ‘Some’ is not exported by 'namespace:mydependency' 

Solution

Add NULL when specifying general directives.

#' @importClassesFrom mydependency niceclass
NULL

#' Some other docs

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Geert van Geest