Problems with loading ggplot2

Hello,
I am presenting problems with ggplot2.
I receive the following notice all the time:
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'

I use RStudio version 1.1.423.
I'm giving my first raids on R
Gracias

1 Like

Hi Hermes,

Here's a stackoverflow post that seems related:

One suggestion there is to first install ggplot2 explicitly installing all dependencies

install.packages(
   "ggplot2",
   repos = c("http://rstudio.org/_packages",
   "http://cran.rstudio.com")
)
#> You may also find it useful to restart R,
#> In RStudio, that's the menu Session >> Restart R

library(ggplot2)

Welcome to community!

Also, when posting code here (or any coding forum), be sure to format your code. This makes it easier for readers to read your post, making it more likely for you to get help. Some tips: FAQ: How to format your code

And this isn't really a RStudio IDE question, it's an R question. So I'm going to move it to the General category.

1 Like

Hi,
Restore both programs:
R-3.4.3-win and on this occasion RStudio-1.1.442
and the problem continues to manifest itself:

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' 

I have made all the recommendations that can be seen in:
lib unspecified & Error in loadNamespace
Gracias

Did you try following the instructions suggested in these StackOverflow answers?
The poster had the exact same error message.

Your error says that Rcpp, a package that ggplot2 depends on, is not yet installed.

You need dependencies = TRUE. Exit and re-open RStudio then run this

install.packages("ggplot2", dependencies = TRUE, repos = "http://cran.us.r-project.org")

I usually use pacman package to manage my packages. It will check if packages are already existed. If not, it will install and load the missing ones
https://cran.r-project.org/web/packages/pacman/vignettes/Introduction_to_pacman.html

Cheers

1 Like

Hi RuReady,
With this little script,

t=seq(0,10,0.1)
y=sin(t)
plot(t,y,type="l", xlab="time", ylab="Sine wave")
library(ggplot2)
qplot(t,y,geom="path", xlab="time", ylab="Sine wave")

I tested the library ggplot2 and got the expected result.
Any other way of knowing if everything is fine with the library ggplot2?

I think the key message of the error message is

  there is no package called 'Rcpp' 

Rcpp is a dependency for ggplot2. It's saying when you try to load ggplot2, it can't because this dependency isn't installed yet.

Some options:

On the home PC I now present the following problem when I try to install a package"~

install.packages("ggplot2", dependencies = TRUE, repos = "http://cran.us.r-project.org")
Warning in install.packages :
  'lib = "C:/Program Files/R/R-3.4.4patched/library"' is not writable
Warning in install.packages :
  cannot create dir 'C:\Users\Macabם', reason 'Permission denied'
Error in install.packages : unable to create ‘C:/Users/Macabם/Tracing/Documents/R/win-library/3.4’
Warning message:
In dir.create(tempPath, recursive = TRUE) :
  cannot create dir 'C:\Users\Macab?', reason 'Invalid argument'
> 

What to do? I've tried reinstalling R & Rstudio, and everything goes on !!!
Gracias

It looks like you do not have write privileges to this directory. Have you tried running it with admin privileges?

1 Like

I ran RStudio with administrator privileges and now I receive the following mesage:

The downloaded binary packages are in
	C:\Users\Macab?\AppData\Local\Temp\Rtmp0kQiqU\downloaded_packages
Warning message:
In dir.create(tempPath, recursive = TRUE) :
  cannot create dir 'C:\Users\Macab?', reason 'Invalid argument'
> 

I'm not sure whether directories can contain characters like '?'.

What is the output of this?
.libPaths()

1 Like
> version
               _                                          
platform       i386-w64-mingw32                           
arch           i386                                       
os             mingw32                                    
system         i386, mingw32                              
status         Patched                                    
major          3                                          
minor          4.4                                        
year           2018                                       
month          03                                         
day            19                                         
svn rev        74426                                      
language       R                                          
version.string R version 3.4.4 Patched (2018-03-19 r74426)
nickname       Someone to Lean On                         
> win.version()
[1] "Windows 7 (build 7601) Service Pack 1"
> .libPaths()
[1] "C:/Program Files/R/R-3.4.4patched/library"
>

Ok, my understanding is that the packages included in the R release are stored in:
C:/Program Files/R/R-3.4.4patched/library

Any packages you download (like you are trying with ggplot2) should be stored by default in a user directory of the form:
C:/Users/<username>/AppData/Local/R/lib

That's how it looks like on my Win 8.1 installation and is likely to be very similar for Win 7.

It looks to me that there is a problem with the '?' in:
C:\Users\Macab?

Is this maybe a non-standard character which is being converted into a '?'. I'm afraid my knowledge does not extend into how such characters are handled by the Windows OS.

There was something wrong with this folder name. Does it have any special/unregular character? You might need to change it or setup another location for all installed packages

https://csgillespie.github.io/efficientR/3-3-r-startup.html#rprofile