R not finding package even after package installation - r

I have always worked with the zoo package, that I have installed a long time ago. Today, I created a new R script, and ran library(zoo) and got the following error:
> library(zoo)
Error in library(zoo) : there is no package called ‘zoo’
Odd.. Still, I tried reinstalling the package using install.packages("zoo"), and get the following:
> install.packages("zoo")
Installing package(s) into ‘C:/Users/U122337.BOSTONADVISORS/Documents/R/win-library/2.15’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
trying URL 'http://cran.cnr.Berkeley.edu/bin/windows/contrib/2.15/zoo_1.7-10.zip'
Content type 'application/zip' length 874474 bytes (853 Kb)
opened URL
downloaded 853 Kb
package ‘zoo’ successfully unpacked and MD5 sums checked
Warning: cannot remove prior installation of package ‘zoo’
The downloaded binary packages are in
C:\Users\U122337.BOSTONADVISORS\AppData\Local\Temp\Rtmp404t8Y\downloaded_packages
When I try uploading the package, I get the error again that the zoo package doesn't exist.
I have no idea what's happening. I exited the GUI and restarted it, same problem. I have always worked with this package, and I have no idea why this is happening now.

Do .libPaths(), close every R runing, check in the first directory, remove the zoo package restart R and install zoo again. Of course you need to have sufficient rights.

When you run
install.packages("whatever")
you got message that your binaries are downloaded into temporary location (e.g. The downloaded binary packages are in
C:\Users\User_name\AppData\Local\Temp\RtmpC6Y8Yv\downloaded_packages ). Go there. Take binaries (zip file). Copy paste into location which you get from running the code:
.libPaths()
If libPaths shows 2 locations, then paste into second one. Load library:
library(whatever)
Fixed.

I had this problem and the issue was that I had the package loaded in another R instance. Simply closing all R instances and installing on a fresh instance allowed for the package to be installed.
Generally, you can also install if every remaining instance has never loaded the package as well (even if it installed an old version).

So the package will be downloaded in a temp folder C:\Users\U122337.BOSTONADVISORS\AppData\Local\Temp\Rtmp404t8Y\downloaded_packages from where it will be installed into your library folder, e.g. C:\R\library\zoo
What you have to do once install command is done: Open Packages menu -> Load package...
You will see your package on the list. You can automate this:
How to load packages in R automatically?

go to this folder C:\Users\hp\Documents\R\win-library\4.0 in your PC.
And delete '00LOCK' named folder.
then It will work properly, THis folder is being locked all incoming file.IF your delete this , then it will work.

Related

Error in loadNamespace Rstudio

I am having real trouble understanding what my problem is installing ggplot package in Rstudio. I have tried a number of the post here and here but I still can't fix the problem.
I understand that I have a library directory on my Windows machine which can be found using:
.libPaths() which returns
[1] "C:/Users/Bo Bo/Documents/R/win-library/3.2" "C:/Program Files/R/R-3.2.3/library"
I'm not sure what is stored in this directory using .Library but it looks to be pointing to the wrong directory, 3.2.3 and 32~1.3???:
[1] "C:/PROGRA~1/R/R-32~1.3/library"
Upon installing ggplot2
install.packages("ggplot2") returns:
Installing package into ‘C:/Users/Bo Bo/Documents/R/win-library/3.2’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.2/ggplot2_2.1.0.zip'
Content type 'application/zip' length 2001769 bytes (1.9 MB)
downloaded 1.9 MB
package ‘ggplot2’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\Bo Bo\AppData\Local\Temp\Rtmp4QKdwV\downloaded_packages
So is it dumping the package in a temp directory because the 'lib' is unspecified? If so how do I specify the 'lib' and which library needs to change.
By the way I followed #Paweł Rumian post in link 2 above meaning I have a new User variable called R_LIBS_USER pointing to C:/Program Files/R/R-3.2.3/library
Can anyone make a suggestion as to how I can resolve this conflict and move on with my life :)
So I ended up re-installing windows after hours of trying to modify/fix the permissions issue I was having with all folders on the local disk.
Since re-installing I have installed Rstudio as per before and I am back in business, no messing around with library locations, just plain vanilla for me please...

unable to access index for repository in R

I am on Windows 7 and I am using R Studio 0.99.902 with R3.3.1. When I am trying to install a package I get the Warnings:
Warning: unable to access index for repository http://cran.rstudio.com/src/contrib:
cannot open URL 'http://cran.rstudio.com/src/contrib/PACKAGES'
Warning: unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/src/contrib:
cannot open URL 'http://www.stats.ox.ac.uk/pub/RWin/src/contrib/PACKAGES'
It is the first time I see it and I cannot solve it. Can anyone help me ?
This issue is likely caused by the package being too old or too new for your R version. For example, if a package is released during R-3.4.1, it will not be available for R-3.3.1. Packages which are removed from CRAN before your R version are also not available. The package DESCRIPTION file shows if there is a hard restriction on which R versions the package will run.
Search for the package's CRAN page and see its status. You may still be able to install the package by downloading the package source (the tar.gz file) and in RStudio selecting Install from: Package Archive File in the Tools/Install Packages... menu (or using install.packages with repos = NULL). Beware that the package is not available from CRAN for a reason; you may need to make some changes to the package for it to work correctly.
Running options(download.file.method="libcurl") then installing packages did the trick for me. You may find an answer here.
Please note that compiling from source for Windows requires the appropriate version of Rtools that is compatible with the R version you are working with. This list is available at the Rtools site:
https://cran.r-project.org/src/contrib/Archive/
If compilation from source is complicated, it is also possible to find the Windows-compiled binaries (.zip files) for older versions of R at:
https://cran-archive.r-project.org/bin/windows/contrib
This link is referenced by the ReadMe file available at the "regular" repository for Windows binaries for different versions of R, namely at:
https://cran.r-project.org/bin/windows/contrib
Once the zip file is downloaded, you can run the following R code line to install the package:
# Use repos=NULL so that the first argument is a path to the local zip file
# containing the binary package to install
# (as opposed to just the name of the package to install from the web)
install.packages("<local-path-to-downloaded-zip-file>", repos=NULL)

"Error in library(rjson): There is no package called rjson"

My rjson package randomly doesn't work. As in, it works fine sometimes, sometimes it fails to load. Not sure why.
I get this error.
Error in library("rjson") : there is no package called ‘rjson’
To try and alleviate this, despite knowing its installed, I added an install line in my script.
install.packages("rjson", repos="http://cran.rstudio.com/")
library(rjson)
Now I get....
Installing package(s) into ‘C:/Users/Tom/Documents/R/win-library/2.15’
(as ‘lib’ is unspecified)
trying URL 'http://cran.rstudio.com/bin/windows/contrib/2.15/rjson_0.2.13.zip'
Content type 'application/zip' length 491848 bytes (480 Kb)
opened URL
downloaded 480 Kb
package ‘rjson’ successfully unpacked and MD5 sums checked
Warning: cannot remove prior installation of package ‘rjson’
The downloaded binary packages are in
C:\Users\Tom\AppData\Local\Temp\RtmpiOfTqK\downloaded_packages
In R, when I go to "Packages --> Load" for some reason rjson is NOT there. It never has been, even when it worked.
I've naviaged to...
C:\Users\Tom\Documents\R\win-library\2.15
I can confirm the folder for rjson is there.
No idea what to do.
This has happened to me quite a few times. It usually happens when you try to install a newer version of an already installed package (although it can happen in other more rare occasions).
The solution I have found so far is to go back to your library path i.e. the location on your machine where the package is installed (C:\Users\user_name\Documents\R\win-library\R_version is the default path on Windows) delete the corresponding package folder and then re-install the package as usual using:
install.packages('rjson')
And this way it should work.
Or you could even do it programmatically as per #Thomas 's comment:
#get list of installed packages
inst_packages <- installed.packages()
if ("rjson" %in% inst_packages[, 1]) {
#uninstalls package
remove.packages("rjson")
#re-installs package
install.packages("rjson")
}
or even better just use:
if ("rjson" %in% inst_packages[, 1]) update.packages("rjson")

Error in R: (Package which is only available in source form, and may need compilation of C/C++/Fortran)

I'm trying to install the 'yaml' and 'stringi' packages in R-Studio, and it keeps giving me these errors:
> install.packages("stringi")
Package which is only available in source form, and may need compilation of C/C++/Fortran: ‘stringi’
These will not be installed
or
> install.packages('yaml')
Package which is only available in source form, and may need compilation of C/C++/Fortran: ‘yaml’
These will not be installed
How can I get these to install properly?
The error is due to R being unable to find a binary version of the package on CRAN, instead only finding a source version of the package and your Windows installation being unable to compile it. Usually this doesn't occur, but in this case was caused by the (temporary) outage of some of the mirrors at CRAN. If you type:
> getOption('repos')
CRAN CRANextra
"http://cran.rstudio.com" "http://www.stats.ox.ac.uk/pub/RWin"
attr(,"RStudio")
[1] TRUE
You will see that R uses "http://cran.rstudio.com" by default to look for a package to download. If you see the cran mirrors web page you can see at the top that "http://cran.rstudio.com" actually redirects you to different servers world wide (I assume according to the geo location).
When I had the above issue, I solved it by manually changing the repo to one of the urls in the link provided. I suggest you use a different country (or even continent) in case you receive the above error.
I provide below some of the urls in case the link above changes:
Brazil http://nbcgib.uesc.br/mirrors/cran/
Italy http://cran.mirror.garr.it/mirrors/CRAN/
Japan http://cran.ism.ac.jp/
South Africa http://r.adu.org.za/
USA https://cran.cnr.Berkeley.edu/
You need to run the function install.packages as follows:
install.packages('<package_name>', repo='http://nbcgib.uesc.br/mirrors/cran/')
#or any other url from the list or link
One of them should then work to install a binary from an alternative mirror.
You need to install RTools to build packages like this (i.e., a source package rather than a binary). After you install Rtools, then try again to install.packages("ggplot2") and R will prompt you with:
Do you want to attempt to install these from source?
y/n:
(see the picture below)
You need to answer y and it will try to compile the package so it can be installed.
Struggled with this issue today, solved it for now by first downloading the windows binary and then installing e.g.
install.packages("https://cran.r-project.org/bin/windows/contrib/3.3/stringi_1.1.1.zip", repos =NULL)
Just go to https://cran.r-project.org/ and then R Binaries/Windows/contrib and copy the url as argument to install.packages()
Install the package from a zip file - downloadable from the r-project website.
In basic R
go to Packages
Install packages from local files.
In RStudio
go to Packages
Install packages
Install from Package Archive File.
I had this issue when using an out-of-date version of R, so no binaries were available. The simple solution was to update my version of R.
Anything worked for me, until I found out my computer had an old version of R installed. Uninstalling everything and installing the newest R version worked!
I had to download the latest version of Rtools:
Go into the downloads folder and double click it to install it.
Close and reopen any R session.
Now packages should install like normal.
However, if you still have trouble, try installing the package from source (using type="source")
Like this:
install.packages("dplyr", type="source")

Unloading and removing a loaded package withouth restarting R

Actual question
Can I unload and remove a package without having to restart an R process that has already required/loaded the package?
I've had a look at this question/answer, but it only deals with part of the problem (unloading)
Background
The reason I want to do this is that I am working on a project-based framework for package development in which I'm also using project-based package libraries in order to keep the standard library "clean" and allow for systematic testing of package dependencies.
The only problem with this is that it's really hard for the user to remember the path to a project-based package library before initializing the project (which also loads all specified package dependencies via require() and makes the project-based library the first one in .libPaths())
Practically, this means that a user currently can't really uninstall a package dependency from the project-based package library in a comfortable way (after initializing the project, that is) and I'm looking for ways to change this.
What I tried
install.packages("forecast")
require("forecast")
detach("package:forecast", unload=TRUE)
remove.packages("forecast")
> install.packages("forecast")
Warning: unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/2.15
trying URL 'http://cran.rstudio.com/bin/windows/contrib/2.15/forecast_4.03.zip'
Content type 'application/zip' length 1124001 bytes (1.1 Mb)
opened URL
downloaded 1.1 Mb
package 'forecast' successfully unpacked and MD5 sums checked
Warning: cannot remove prior installation of package 'forecast'
The downloaded binary packages are in
C:\Users\wwa418\AppData\Local\Temp\RtmpYPry89\downloaded_packages
The problem seems to be /forecast/libs/i386/forecast.dll which probably gets registered upon loading and seems to be a tough one to kill ;-)
Any ideas?

Resources