I am trying to create a package in R wherein I have created lots of new custom Classes. Each class is in a different file. The Classes inherit from a parent class and inherit to other classes.
While running my codes I call each of them like this
source("package/father.R")
source("package/son.R")
source("package/grandson.R")
Definition for Some of the methods needed by the grandson Class in defined in Son class. I use package.skeleton() to call each of them and create a package and it seems to work fine. But when running R CMD Check(and when trying install into R), it throws an error because the function tries to call the files in the alphabetical order and so the file grandson.R is called before son.R and it shows and error saying that the methods has not been defined. If I change the names to zgrandson.R, R called that file the last, and everything seems to work fine, but this is evidently not a solution for the problem.
I have read tutorials for creating packages, but all of them seem to deal with simple cases where there is no inheritance/calling other files in R. Hope I have made myself clear.
As far as I understand, you can use the
Collatefield in theDESCRIPTIONfile to control this.Quoting from the Writing R Extensions manual:
So, you could specify:
Or simply rename the files in such a way that lexicographic sorting order will result in the correct collation order, as you indicated in your question.
But also see this answer by @DirkEddelbuettel on a similar question.