I can't load "ggplot2" in my library in R version 3.4.3

When I start to install "ggplot2" pacakages following this command on R studio 1.1.442, it gets installed but with following information shown in the console:

> library("ggplot2")
Error: package or namespace load failed for ‘ggplot2’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
 there is no package called ‘Rcpp’
In addition: Warning message:
package ‘ggplot2’ was built under R version 3.4.4 

Afterwards, as it's mentioned above regarding package of "Rcpp", I made another command to install it and it gets installed with following information:

> install.packages("Rcpp")
Installing package into ‘C:/Users/User/Documents/R/win-library/3.4’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.4/Rcpp_0.12.16.zip'
Content type 'application/zip' length 4371492 bytes (4.2 MB)
downloaded 4.2 MB

package ‘Rcpp’ successfully unpacked and MD5 sums checked
Warning in install.packages :
  unable to move temporary installation ‘C:\Users\User\Documents\R\win-library\3.4\file1b4848d92905\Rcpp’ to ‘C:\Users\User\Documents\R\win-library\3.4\Rcpp’

The downloaded binary packages are in
	C:\Users\User\AppData\Local\Temp\RtmpWAhEmJ\downloaded_packages

Afterwards, I try to load "ggplot2" package in R, but it doesn't gets loaded and shows the same previous command.

> library("ggplot2")
Error: package or namespace load failed for ‘ggplot2’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
 there is no package called ‘Rcpp’
In addition: Warning message:
package ‘ggplot2’ was built under R version 3.4.4 

Please do help, what should I do to resolve this issue?

The problem you have is with the Rcpp not completing properly.

Try the steps in this post:

1 Like

This is likely your Anti-Virus stopping the move from the temp directory to its permanent home. It can happen in corporate environments. Try the following:
In the console type:
trace(utils:::unpackPkgZip,edit = T)

Then edit Line 140 Sys.sleep(0.5) to Sys.sleep(2)

Now try to install Rccp. Note this will only last until you restart your R session, but if you usually don’t have issues installing R packages that’s not an issue. Just remember to do that whenever you have to install an r package that is too big for your Anti-Virus to scan before R tries to move it.

1 Like

I went through this trouble with unable to move temporary installation just recently, I tried all the other solutions, but none worked for me. However, what I was able to do was update my laptop, copy and paste the directory with all the packages into my other computer. Works perfect now, no more problems.

I tried this but it didn't work for me.
I guess i need more privileges to install packages in R using a work computer.
How do I explain the IT guy this problem?
Thanks in advance!

Try installing Rcpp within R (not RStudio) with administrative privilege.

On windows, right click on an R shortcut and select "run as administrator" to launch R. On linux, run R with sudo R .

If this works, then try installing ggplot2.