Dear All, I'd like to change the options("contrasts") within a function, such that "identity" contrasts are created for unordered factors. I'm following the idea shown below, which works fine.
However, when I include these functions in a package (with `contr` being exported, but `contr_identity` not exported as it is not intended to be called directly by the user), I get the following error message. And this is after loading and attaching the package with library(). Why is `contr_identity` not found? Error in get(ctr, mode = "function", envir = parent.frame()) : object 'contr_identity' of mode 'function' was not found contr <- function(x) { ocontrasts <- options(contrasts = c(unordered = "contr_identity", ordered = "contr.diff")) on.exit(options(ocontrasts)) contrasts(x) } contr_identity <- function(n, contrasts) { contr.treatment(n, contrasts = FALSE) } f <- gl(2, 8, labels = c("Control", "Treat")) contrasts(f) contr(f) Thanks, Axel. [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.