Open mjskay opened 3 years ago
Thx
I just wanted to swing back around here to say: we were able to work around this by manually attaching and detaching the {caret} namespace and those of its hard dependencies (ggplot2, lattice). If anyone else encounters this issue and is curious, our workaround is here: https://github.com/stan-dev/posterior/pull/181.
So while it might still technically be an issue, we no longer need a solution for our purposes --- so please feel free to close this if you want :). Thanks!
Thanks for the wonderful package! We've been using caret to implement an algorithm for the
rstar()
function in the posterior package. This function internally fits a model usingcaret::train()
in order to calculate an MCMC diagnostic.We've run into an issue: we would not like our users to have to load/attach the {caret} namespace just to use the
rstar()
function. However, we have found some configurations ofcaret::train()
we would like to use (particularly whenmethod = "knn"
) appear to require the {caret} namespace to be attached or they will fail. We were wondering if this is a bug, or if there is something more fundamental about the setup of {caret} such that it is only intended to work if the user has attached its namespace.I provide an example and some more explanation below.
Minimal, reproducible example:
Minimal dataset:
Just a simple dataset with one continuous predictor (
x
) and a response variable with two classes (y
):Minimal, runnable code:
NOTE: To see the problem this must be run without {caret} loaded into the namespace:
Here's a minimal example of the problem. I provide some other investigation into the issue afterwards in case it is helpful.
Assuming caret is not loaded, run the following code:
This problem does not happen if:
method
s (e.g.,method = "rf"
) are used (I have not tested all methods)library(caret)
is run firsttrControl
is left at its default value.Here is the output if we use the default value of
trControl
; which works (with a caveat, see below):The caveat is, this appears to have worked because {caret} has loaded and attached its own namespace (as well as the namespaces of its two hard dependencies, ggplot2 and lattice), as we can see if I now check attached packages:
Currently, we are working around this by throwing a warning and asking users to run
library(caret)
manually (see https://github.com/stan-dev/posterior/issues/164). However, ideally we would not like to require users to attach caret, ggplot2, and lattice to their namespace in order to call therstar()
function.Any help would be much appreciated. Thanks!
Session Info: