[Rd] Automatically retrieve correct collation
Janko Thyson
janko.thyson at ku-eichstaett.de
Wed Aug 18 22:28:54 CEST 2010
Dear List,
consider the following scenario:
setClass(Class = "A", representation = representation(B = "B", C = "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, A. Which
doesn't correspond to the default collation of R (alphabetically).
I've tried to pick up on how to ensure the right collation when building R
Packages by reading some previous posts and as far as I understand I've
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 DESCRIPTION
file.
I'm used to organizing my classes, generics, methods etc. on a
"one-per-script" basis in various subdirectories (e.g. R/classes, R/methods
etc.) and try automate manual steps wherever possible (not sure if that's
the way most of you guys code, but it definitely helped me stay on top of
things). But this doesn't really go well with my two options above, does it?
;-)
So I thought about setting up a routine that
- investigates the source code of all classes (via parsing and looking into
the "representation" argument)
- finds out the valid collation by itself based on all classes that it found
in the representation argument of the respective class defs
- and then writes all the class defs to one R script, e.g. allClasses.R, so
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 of
building a package a bit ;-)
Now, I managed to get this done for "simple" class defs like the ones above
but haven't looked into more complex class defs (e.g. including "contains"
etc.) yet.
Has anyone tried and succeeded in doing something similar or are all of you
into the "one-script-contains-all" paradigm? If anyone is interested, I'd be
glad to share code. Likewise I'd be interested in hearing about other "best
practices" in this respect.
Best regards,
Janko
More information about the R-devel
mailing list