Receiving error when installing ggplot2

I need to install ggplot2 but keep getting an error:

Error in install.packages : cannot open file 'C:/Users/Patricia/Documents/R/win-library/3.5/file2a186f8351d5/glue/help/figures/logo.png': Permission denied

I have uninstalled and reinstalled R Studio and have run as administrator. Makes no difference.

How do I fix this?

Hi Patricia! Welcome!

That error can sometimes be caused by anti-malware software, including Windows Defender (usually the “Controlled Folder Access” anti-ransomware feature). You may need to whitelist R and RStudio, or (temporarily!) turn off the malware protection while you install.

Do either of those options work?

2 Likes

Thank You!!

You were right........ my Anti Virus was blocking the program. I have white-listed both R and R Studio and have downloaded ggplot2.

It's turned out to be a temporary fix.... Received 2 more similar messages, different file names but otherwise the same structure. I decided to try to add the following to my Anti-Virus exception paths to see if it would get around it: C:/Users/Patricia/Documents/R/win-library/3.5/* - but it didn't work.

I was able to download another package without a hitch.... and Windows Defender has been turned off. Any advice appreciated, thanks.

I’m sorry you’re still having trouble! Unfortunately, we’re getting to the sort of really system-specific stuff that can be challenging to debug from afar. Some questions/things to try:

  1. Are you running RStudio as administrator when you install packages, in addition to changing your anti-virus settings?
  2. Since R moves things around a bit during installation (which can look suspicious to anti-malware software), you might try making the exclusion path the entire C:/Users/Patricia/Documents/R/ directory.
  3. I have heard some people in this situation say they have more success installing packages (as administrator) from R, rather than from RStudio — not sure if that’s for real or not, but I guess it might look different from the perspective of the anti-malware program.
  4. Are you on a computer where somebody else has influence over the anti-malware configuration (such as a work computer)? If so, you might need to talk to them.
  5. Moving your R library somewhere other than your User directory sometimes helps, since the stuff in that directory gets extra attention from anti-malware software (due to the threat of ransomware, mostly). There’s a good discussion of different ways to do this here: Help regarding package installation: .Renviron, .Rprofile, R_LIBS, R_LIBS_SITE, and R_LIBS_USER Oh my!
1 Like