How to specify in which order to load S4 methods when using roxygen2

后端 未结 1 1454
灰色年华
灰色年华 2021-02-20 15:36

I ran into following problem already multiple times.

Say you have two classes, classA and classB described in the following files classA.

相关标签:
1条回答
  • 2021-02-20 15:43

    There are two ways to achieve this:

    As described in ?collate_roclet, you can use the @include tag to specify which class should be read before which. In this case, you can add to the file classB.r the following line right before the actual R code:

    #' @include classA.r
    

    These tags are read specifically to update the Collate field in the DESCRIPTION file, and are the recommended way of dealing with the problem.

    In some cases the dependencies might be so complex you want to keep an overview yourself and not rely completely on adding @include tags in your codebase. In that case you can just specify the Collate field at the end of the DESCRIPTION file, like this:

    Package: myExample
    Type: Package
    ...
    Collate:
        'classA.R'
        'classB.R'
    

    The function roxygenize() first checks the DESCRIPTION file, and loads whatever files are specified there first in the order they're specified. Only then the rest of the package is loaded.

    0 讨论(0)
提交回复
热议问题