Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: package or namespace load failed for ggplot2 and for data.table

I am not able to open install the ggplot2 and data.table packages. It gives me the following error (example for ggplot2)

> library(ggplot2) Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) :    there is no package called ‘Rcpp’ Error: package or namespace load failed for ‘ggplot2’ 

I was able to work fine with these 2 packages before I closed my R session. Now it shows me this error each time I try to run it.

I have also tried to remove and re-install it, but without success.

remove.packages(c("ggplot2", "data.table")) install.packages('ggplot2', dep = TRUE) install.packages('data.table', dep = TRUE) 

I am not sure what's wrong

like image 475
elisahmendes Avatar asked Jul 30 '15 07:07

elisahmendes


2 Answers

After a wild goose chase with tons of Google searches and burteforce attempts, I think I found how to solve this problem.

Steps undertaken to solve the problem:

  1. Uninstall R
  2. Reinstall R
  3. Install ggplot with the dependencies argument to install.packages set to TRUE

    install.packages("ggplot2",dependencies = TRUE)

  4. The above step still does NOT include the Rcpp dependency so that has to be manually installed using the following command

    install.packages("Rcpp")

However, while the above command successfully downloads Rcpp, for some reason, it fails to explode the ZIP file and install it in my R's library folder citing the following error:

package ‘Rcpp’ successfully unpacked and MD5 sums checked Warning in install.packages : unable to move temporary installation ‘C:\Root_Prgs\Data_Science_SW\R\R-3.2.3\library\file27b8ef47b6d\Rcpp’ to ‘C:\Root_Prgs\Data_Science_SW\R\R-3.2.3\library\Rcpp’

The downloaded binary packages are in C:\Users\MY_USER_ID\AppData\Local\Temp\Rtmp25XQ0S\downloaded_packages

  1. Note that the above output says "Warning" but actually, it is an indication of failure to install the Rcpp package successfully within the repository. I then used the Tools-->Install packages--> From ZIP file and pointed to the location of the "downloaded binary packages" in the message above -

C:\Users\MY_USER_ID\AppData\Local\Temp\Rtmp25XQ0S\downloaded_packages\Rcpp_0.12.3.zip

  1. This led to successful installation of Rcpp in my R\R-3.2.3\library folder, thereby ensuring that Rcpp is now available when I attempt to load the library for ggplot2. I could not do this step in the past because my previous installation of R would throw error stating that Rcpp cannot be imported. However, the same command worked after I uninstalled and reinstalled R, which is ODD.

    install.packages("C:/Users/MY_USER_ID/AppData/Local/Temp/Rtmp25XQ0S/downloaded_packages/Rcpp_0.12.3.zip", repos = NULL, type = "win.binary") package ‘Rcpp’ successfully unpacked and MD5 sums checked`

  2. I was finally able to load the ggplot2 library successfully.

    library(ggplot2)

like image 25
Rdsprg Avatar answered Sep 29 '22 19:09

Rdsprg


This solved the issue:

remove.packages(c("ggplot2", "data.table")) install.packages('Rcpp', dependencies = TRUE) install.packages('ggplot2', dependencies = TRUE) install.packages('data.table', dependencies = TRUE) 
like image 149
elisahmendes Avatar answered Sep 29 '22 18:09

elisahmendes