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

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")

Related

Installation directory?

I'm trying to install Tidytext package. It seems to me that R is installing the package into my OneDrive. I've been using R and I've not run into this problem before. I've unsynchronized One Drive and done a variety of things to change my working drive, but I still get the following message when installing Tidytext package -
Installing package into "C:/Users/Anjan/OneDrive/Documents/R/win-library/3.5"
(as "lib" is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/tidytext_0.2.0.zip'
Content type 'application/zip' length 2836849 bytes (2.7 MB)
downloaded 2.7 MB
I've unsynchronized One Drive from my Documents folder on This PC.
I've checked getwd()
I've set setwd()
I've used Tools and Global Options and changed my working directory.
But R still uses One Drive. How do I get R to not use One Drive?
install.packages("tidytext")
Installing package into "C:/Users/Anjan/OneDrive/Documents/R/win-library/3.5"
(as "lib" is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/tidytext_0.2.0.zip'
Content type 'application/zip' length 2836849 bytes (2.7 MB)
downloaded 2.7 MB
package ‘tidytext’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\Anjan\AppData\Local\Temp\RtmpYDylTE\downloaded_packagesinstall.packages("magritte")
Installing package into "C:/Users/Anjan/OneDrive/Documents/R/win-library/3.5"
(as "lib"is unspecified)
Warning in install.packages :
package ‘magritte’ is not available (for R version 3.5.3)
getwd()
[1] "C:/Users/Anjan/OneDrive/Documents"
Use this to see actual library paths:
.libPaths()
And the same to set another destination folder to install:
.libPaths(PATH_THAT_YOU_WANT)
You can also specify a location like we see here:
Install R package to a specific directory
Take a look into the docs:
https://rdocumentation.org/packages/base/versions/3.6.1/topics/libPaths
It's a bug, reported at https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17842.
R should never put libraries in a user's documents folder. That is an inappropriate use of that folder, and there are better places for this kind of data.

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...

Installing ZeligMultilevel. Error : object ‘describe’ is not exported by 'namespace:Zelig'

I am trying to use ZeligMultilevel but I am having problems when opening the library. Please, see below:
> install.packages("ZeligMultilevel")
trying URL
'http://cran.rstudio.com/bin/windows/contrib/3.2/ZeligMultilevel_0.7-1.zip'
Content type 'application/zip' length 267971 bytes (261 KB) downloaded
261 KB
package ‘ZeligMultilevel’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\AppData\Local\Temp\RtmpkHO9ls\downloaded_packages
> library(ZeligMultilevel)
Error : object ‘describe’ is not exported by 'namespace:Zelig'
Error:package or namespace load failed for ‘ZeligMultilevel’
I already tried installing it with dependencies=TRUE. I also tried installing ZeligMultilevel from the source and I have the same problem. I think there must be a tiny silly thing that I am missing, but I cannot find what to do...
Any idea?
Thanks
It looks like there is a compatibility problem between the latest version of the Zelig package and ZeligMultilevel. Notice that the latest version of Zelig was uploaded about a week ago.
Try downloading an older version of Zelig and installing that.
https://cran.r-project.org/src/contrib/Archive/Zelig/
Installing the Zelig_4.2-1.tar.gz from the 21-Sep-2013 worked for me.

R not finding package even after package installation

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.

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