[R] Define package-wide character constants

Daniel Nüst daniel.nuest at gmail.com
Tue Jul 13 14:20:56 CEST 2010


Dear list!

I develop a package for R and wonder how I can best define
package-wide constants (both character strings or named vectors of
strings) which are used throughout different classes and methods. I'm
new to R and wonder if there is some kind of “best practice” that I
just haven't read of yet. My main programming language is Java, so if
that helps anyone to understand my thinking: I mean values that I
would normally put into a class like Constants.java as “public static
final” variables, or into a .properties file.

A concrete example: I deal with XML files, both parsing and encoding.
Right now I have several classes representing documents which I
handle, and in each of the encoding methods there is a character
string for the schema location. If I want to change that location then
I have to change it several times (neglecting search and replace), but
I'd rather have a single point of change for that.

I've read documentation on environments, "<<-" and the "assign"
function, BUT am still not sure how to approach my problem BEST.
"assign" could most probably do the job, but do I use/create a certain
environment (like "myConstants")? Or should I just use my package's
environment?


Thanks for any experiences, (alternative) ideas, or pointers at
existing discussions!

Regards,
Daniel



More information about the R-help mailing list