I need to run 2 different scripts in R without restarting the session. In the first i use the package mgcv
and in the second i need gam
. I wrote a script which detaches and removes the package mgcv
and installs and loads gam
.
But still after i want to run the gam() function I get an error telling me that mgcv
was not found. Which I interpret as R looking for the mgcv
package for installing it...
Here's a MWE:
install.packages(paste(path.pkgs,'mgcv_1.8-7.zip',sep=''),repos=NULL)
require(mgcv)
## FIRST SCRIPT ##
detach(package:mgcv)
remove.packages('mgcv')
unloadNamespace('mgcv')
require(gam)
## SECOND SCRIPT ##
gam(as.formula(t.thr.fm),data=data)
which returns the error:
Error in get(method, envir = home) :
cannot open file 'H:/data/Documents/R/R-3.1.3/library/mgcv/R/mgcv.rdb': No such file or directory
Any ideas instead of restarting the session?
EDIT:
The solution suggested by Floo0 using package::function is unfortunately not an option.
you can tell R to take a function from a specific package via this syntax:
package::function
So in your case (do not detach mgtv
) and use
mgcv::gam(...)
gam::gam(...)
If the function is not exported in the namespace of the function you can also try package:::function
with 3 :