On 18 August 2010 22:28, Janko Thyson <janko.thyson at ku-eichstaett.de>
wrote:
Dear List,
consider the following scenario:
setClass(Class = "A", representation = representation(B = "B", C =
setClass(Class = "B", representation = representation(C = "C"))
setClass(Class = "C", representation = representation(something =
"character"))
Obviously, the collation for sourcing these defs needs to be: C, B,
doesn't correspond to the default collation of R (alphabetically).
I've tried to pick up on how to ensure the right collation when
Packages by reading some previous posts and as far as I understand
basically got two options here:
1) Put all class defs in one script, e.g. allClasses.R.
2) Manually specify the collation via the "Collate" field in the
file.
I'm used to organizing my classes, generics, methods etc. on a
"one-per-script" basis in various subdirectories (e.g. R/classes,
etc.) and try automate manual steps wherever possible (not sure if
the way most of you guys code, but it definitely helped me stay on
things). But this doesn't really go well with my two options above,
;-)
So I thought about setting up a routine that
- investigates the source code of all classes (via parsing and
the "representation" argument)
- finds out the valid collation by itself based on all classes that
in the representation argument of the respective class defs
- and then writes all the class defs to one R script, e.g.
I can bundle all my code in an R Package without worrying about the
collation.
This way I could stick to my old habits while automating the process
building a package a bit ;-)
Now, I managed to get this done for "simple" class defs like the ones
but haven't looked into more complex class defs (e.g. including
etc.) yet.
Has anyone tried and succeeded in doing something similar or are all
into the "one-script-contains-all" paradigm? If anyone is interested,
glad to share code. Likewise I'd be interested in hearing about other
practices" in this respect.
Best regards,
Janko