r-lib / R6

Encapsulated object-oriented programming for R
https://R6.r-lib.org
Other
412 stars 57 forks source link

Suppress export of R6 classes in R package when they are private member fields of exported class #264

Closed ilyaZar closed 2 years ago

ilyaZar commented 2 years ago

Setup with R package using R6:

I have a class A with private fields which are themselves classes e.g. classB1, classB2 etc. All classes are documented, but only class A has an @export tag (because it's meant for the end-user).

Also, public members from class A (which are meant to be the end-user interface i.e. getters/setters) provide access, via above private fields to public member functions of classB1, classB2.

Aim: I want to document all classes A,B1,B2,... but explicitly do not want to export classB1, classB2. Still I want to have the documentation of classB1, classB2 for internal development to be accessible via ?pkgName::classB2.

Currently, I have access to pkgName::classB1, though it should be only accessible via pkgName:::classB1, or am I missing something obvious here?

Is that intended or a bug? If intended, is it possible to suppress exporting explicitly (i.e. only allow pkgName:::classB1 but not pkgName::classB1)?

gaborcsardi commented 2 years ago

What is exported and what is not exported does not have much to do with R6. The NAMESPACE file configures the exported objects of a package.

You probably need to remove the classes you don't want to export from NAMESPACE. Or, if you use roxygen2 to generate NAMESPACE, then you need to remove @export tags and re-generate the NAMESPACE file.

ilyaZar commented 2 years ago

Thanks, there was an @export tag hidden in the problematic subclass!