Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8887451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:48:41+00:00 2026-06-14T21:48:41+00:00

I ran into following problem already multiple times. Say you have two classes, classA

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T21:48:43+00:00Added an answer on June 14, 2026 at 9:48 pm

    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
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran into the following problem. I have two different packages in package a
Today I ran into the following problem with NUnit. I have a class, that
Never ran into this problem with jQuery before. I have the following: $(document).ready(function() {
I ran into the following problem. I have an xml-file like this: <Source Name
I ran into the following problem and cannot decide how to proceed: I have
I am creating a PHP site and have ran into the following problem, i
I ran into the following problem. I have a table like this: ID ID1
I have ran into a bit of problem. Originally, I have the following input
I'm currently preparing a major Program-Update and ran into following problem: I've got a
In my class design I ran into the following problem: class MyData { int

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.