I've installed two packages, "lmtest" and "sandwich". When I try to run a package, R says that there is no package with the name though it has already said that it was successfully downloaded. I've already uninstalled and reinstalled R, I've removed the packaged and reinstalled them and restarted R, closed the notebook and reopened he notebooks -- nothing has worked. I've also checked my firewall and R is let through it.
package ‘lmtest’ successfully unpacked and MD5 sums checked
Warning in install.packages :
cannot remove prior installation of package ‘lmtest’
The downloaded binary packages are in
C:\Users---\AppData\Local\Temp\RtmpGaJ4vT\downloaded_packages
Installing package into �C:/Users/Emily/OneDrive/Documents/R/win-library/3.5�
(as �lib� is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/sandwich_2.4-0.zip'
Content type 'application/zip' length 1315938 bytes (1.3 MB)
downloaded 1.3 MB
package ‘sandwich’ successfully unpacked and MD5 sums checked
Warning in install.packages :
cannot remove prior installation of package ‘sandwich’
The downloaded binary packages are in
C:\Users---\AppData\Local\Temp\RtmpGaJ4vT\downloaded_packages
C:\Users---\AppData\Local\Temp\RtmpGaJ4vT\downloaded_packagesal\Temp\RtmpGaJ4vT\downloaded_packagesly\AppData\Local\Temp\RtmpGaJ4vT\downloaded_packagesta\Local\Temp\RtmpGaJ4vT\downloaded_packages
sandwich::standwich(bptest(mod.h))
Error in loadNamespace(name) : there is no package called ‘sandwich’
sandwich::bptest(mod.h)
Error in loadNamespace(name) : there is no package called ‘sandwich’
bptest(mod.h)
Error in bptest(mod.h) : could not find function "bptest"
It looks like the library folders are locked, and can't be overwritten.
The key pieces of information, to me, are
Installing package into �C:/Users/---/OneDrive/Documents/R/win-library/3.5�
and
cannot remove prior installation of package ‘lmtest’
In my experience, when this happens, I usually go to C:/Users/---/OneDrive/Documents/R/win-library/3.5, delete the lmtest folder. With the folder deleted, install.packages should be able to write the package.
There's probably a more elegant way to do this, but that's the solution I've been using.
library(sandwich)
(this message popped up): Error in loadNamespace(name) : there is no package called ‘sandwich’
that happened but when I ran the tests I needed such as the bptest and coeftest, they ran. So clearly it's running tests but do you know if I should be concerned about the previous "there is no package called 'sandwich'" message?
Will the test still normally if I close R and reopen it later?
Try to re-install the packages with administrative privilege:
close RStudio
right click on a R (not RStudio) shortcut
select "Run as administrator"
re-install both packages (same command you used before in RStudio)
close R
re-open RStudio
Note: I tried to reply by email a while ago, but either there is a very long delay or something went wrong. But a duplicate of this reply might popup at some point.
Yes: your solution is a workaround: since you don't have the right privileges to write in your library from within R, you do it manually. With administrative privilege, this should work without having to go edit your library manually. Working from within R with the right privileges is a lot cleaner because R will take care of dependencies properly.
I would You might have only manually deleted lmtest, but not sandwich? In any case, I would try to reinstall both as I suggested.
HI, I uninstalled and reinstalled R and R Studio then did as you suggested. When I reran my bptest, it said that there was not such thing as a bptest. When I ran "library(sandwich)" it said there was not such thing as sandwich.
bptest(log.mod)
Error in bptest(log.mod) : could not find function "bptest"
library(sandwich)
Error in library(sandwich) : there is no package called ‘sandwich’
But when I did the other thing and deleted the file "lmtest", everything worked. And I think the file may popped back up again after I reinstalled the packages (I left the file explorer page open and saw it had returned when I wet to closed everything out and uninstall R and R Studio).
So what should I do now? I'm confused about what's happening with my computer and R and R Studio. Thanks
and then tried running my bptests and coeftests. The problem now is that after installing it, the functions I need to use that should have been installed with the packages aren't recognized, even when I have done:
sandwich::sandwich(bptest(mod.h))
lmtest::lmtest(bptest(mod.h))
.
etc.
.
bptest(mod.h)
The first solution worked but the packages I installed weren't recognized if I said "library(sandwich)" or "library(lmtest)". So I uninstalled and installed R and tried the second solution. That didn't work and the test I wanted to run weren't tests that R recognized. Even though the first solution offered work, but I was worried that I didn't know exactly what I was doing, that the packages were recognize, and what type of problems it could cause later down the road.
Could you please turn this into a self-contained reprex (short for minimal reproducible example)? It will help us help you if we can be sure we're all working with/looking at the same stuff.
If you run into problems with access to your clipboard, you can specify an outfile for the reprex, and then copy and paste the contents into the forum.
HI Hi -- Thanks for the help. For some strange reason, it started working. I think it probably had something to do with restarting things. I can't be certain but my problem has been solved but I'll look into learning about reprex for future reference.