-
Notifications
You must be signed in to change notification settings - Fork 637
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dummyVars: contr.ltfr not found if caret not attached #380
Comments
Out of curiosity, why not? I don't know of an easy method. You could always just copy the code from this package and do a proper attribution. That's not pretty but I don't know of any cleaner way than this or importing it.
I don't see this... > library(caret)
Loading required package: lattice
Loading required package: ggplot2
options("contrasts")
nope <- capture.output(example("dummyVars"))
options("contrasts")
> options("contrasts")
$contrasts
unordered ordered
"contr.treatment" "contr.poly"
> nope <- capture.output(example("dummyVars"))
> options("contrasts")
$contrasts
unordered ordered
"contr.treatment" "contr.poly" The code has if(!object$fullRank)
{
oldContr <- options("contrasts")$contrasts
newContr <- oldContr
newContr["unordered"] <- "contr.ltfr"
options(contrasts = newContr)
}
<snip>
if(!object$fullRank) options(contrasts = oldContr) |
I wanted to keep caret an optional dependecy, so any import would have to be conditional (depending on whether caret is installed). At runtime, this is possible via require(), but CRAN does not like this, so I use requireNamespace() (as seen here), which does not attach the package.
Ah, yes, my bad. This only happens if the caret package is not attached becuse then an error occurs between setting and resetting of the contrasts and they are never reset. I guess I will just make caret an |
Hello,
I'm using caret for optional pre-processing in another package. This means I have caret in the suggests field of the DESCRIPTION file, and do not directly import from it, but call its functions using the namespace prefix
caret::
. In this context, there is a small bug with thedummyVars
function, which registers thecontr.ltfr
function in the options, assuming that it is available in the global environment. Here is a minimal example to reproduce the error (note that I do not calllibrary(caret)
intentionally):I work around this by exporting my own version of contr.ltfr which calls
caret::contr.ltfr
, so it is not a big deal, and maybe using caret withoutlibrary
'ing or importing it completely is not a scenario you want to support, that would be fine as well. I just wanted to let you know, maybe there is an easy solution or fix.Something else I have thought about: You do not seem to reset the "contrasts" option, so a call to dummyVars creates side-effects (any function using the "contrasts" option after this may behave differently), is this intentional?
Thanks, keep up the good work on this great package.
The text was updated successfully, but these errors were encountered: