I am using neuralnet
to train neural networks. The package, more specifically the plotting function of neuralnet
, depends on grid
, which is a base package since last year. However, unless I load grid
manually, the plotting fails:
AND <- c(rep(0,7),1)
OR <- c(0,rep(1,7))
binary.data <- data.frame(expand.grid(c(0,1), c(0,1), c(0,1)), AND, OR)
net <- neuralnet::neuralnet(AND + OR ~ Var1 + Var2 + Var3, binary.data,
hidden = 0, linear.output=FALSE)
if(requireNamespace("grid")) {
neuralnet::plot.nn(net)
}
> Error in plot.nn(net, rep = i, x.entry, x.out, radius, arrow.length, intercept, :
> could not find function "grid.newpage"
Using library(grid)
helps, but I want to avoid that because I want to use it in my own package later. R Packages suggests using requireNamespace
, but that doesn't help either, as we can see above.
Adding grid::
in front of all calls to grid
functions and building the package from source solves the issue, but I'm wondering: is that intended behavior? Looking at the sources of neuralnet
, I find no mention of requireNamespace
, library
or similar. But then why doesn't my requireNamespace
take care of loading the package?