GGPLOT2 packagde installation/loading error

Hi all,

I'm pretty new to R, and am having problems loading the "ggplot2" package.

My code :
install.packages("ggplot2")
library("ggplot2")

Gives the error:

Error: package or namespace load failed for ‘ggplot2’ in rbind(info, getNamespaceInfo(env, "S3methods")): number of columns of matrices must match (see arg 2)

Does anyone know how to fix this?
-Ash

1 Like

Just remove the quotemarks in

library(ggplot2)

I finally figured it out partially by remembering that before installation, R doesn't know anything about ggplot2, so you have to quote it to say "there's this thing called ggplot2, go to the usual place and search for it." After installation, R has it internally, so no quotes needed.

Hey,

I have tried it without quotation marks, and I still get the same error....

Ash

Well, tell us some more about your setup:

Operating system version
R version
RStudio, if you're using it
Whether you're installing from the R console

> install.packages("ggplot2")

or from the RStudio console pane from the RStudio (same command)

Operating system version: Windows 7 Enterprise (64-bit operating system)
R version: 3.5.2
I am using RStudio version 1.2.1335
I am installing from the RStudio console pane :slight_smile:

OK, that help's. R 3.5.2 rather than 3.6.0 shouldn't be a problem. Windows 7 could be, but I am about 15 years out of day. Let me see what I can find on this, focusing on W7. I did see 1 Win error message for another package.

1 Like

What do you get when you run


sapply(allpackages, function(x) 
ncol(asNamespace(x)$.__NAMESPACE__.$S3methods))

I get this error:

Error in lapply(X = X, FUN = FUN, ...) : object 'allpackages' not found

Well, back to the drawing board. Let go back and try something simpler

remove.packages("ggplot2")
install.packages("ggplot2

(I just did this to be sure of the quotes. The theory is that your download may have been corrupt.)

I get the original error when I try to load ggplot2:

package �ggplot2� was built under R version 3.5.3Error: package or namespace load failed for ‘ggplot2’ in rbind(info, getNamespaceInfo(env, "S3methods")):
number of columns of matrices must match (see arg 2)

Here's a function that will actually do something and help identify any package conflicts. I just ran it on Mojave and removed a couple of recent packages with some S3 conflicts:

allPackages <- installed.packages()[, 1]
findBrokenPackages <- function(packages) {
    for (p in packages) {
        tryCatch(ncol(asNamespace(p)$.__NAMESPACE__.$S3methods),
                 error = function(e) print(c(p, e)))
    }
}
findBrokenPackages(allPackages)

SO

I get the following:

findBrokenPackages(allPackages)
[[1]]
[1] "cowplot"

$message
[1] "number of columns of matrices must match (see arg 2)"

$call
rbind(info, getNamespaceInfo(env, "S3methods"))

[[1]]
[1] "dplyr"

$message
[1] "package ‘assertthat’ does not have a namespace"

$package
[1] "assertthat"

package.lib [1] "\\\\INFPWFS221.ad.unsw.edu.au/Student046/z5059502/R/win-library/3.5"

$call
NULL

[[1]]
[1] "ggplot2"

$message
[1] "number of columns of matrices must match (see arg 2)"

$call
rbind(info, getNamespaceInfo(env, "S3methods"))

[[1]]
[1] "ggpubr"

$message
[1] "number of columns of matrices must match (see arg 2)"

$call
rbind(info, getNamespaceInfo(env, "S3methods"))

[[1]]
[1] "ggrepel"

$message
[1] "number of columns of matrices must match (see arg 2)"

$call
rbind(info, getNamespaceInfo(env, "S3methods"))

[[1]]
[1] "ggsci"

$message
[1] "number of columns of matrices must match (see arg 2)"

$call
rbind(info, getNamespaceInfo(env, "S3methods"))

[[1]]
[1] "munsell"

$message
[1] "number of columns of matrices must match (see arg 2)"

$call
rbind(info, getNamespaceInfo(env, "S3methods"))

[[1]]
[1] "scales"

$message
[1] "number of columns of matrices must match (see arg 2)"

$call
rbind(info, getNamespaceInfo(env, "S3methods"))

[[1]]
[1] "assertthat"

$message
[1] "package ‘assertthat’ does not have a namespace"

$package
[1] "assertthat"

package.lib [1] "\\\\INFPWFS221.ad.unsw.edu.au/Student046/z5059502/R/win-library/3.5"

$call
NULL

[[1]]
[1] "cli"

$message
[1] "package ‘cli’ does not have a namespace"

$package
[1] "cli"

package.lib [1] "\\\\INFPWFS221.ad.unsw.edu.au/Student046/z5059502/R/win-library/3.5"

$call
NULL

[[1]]
[1] "colorspace"

$message
[1] "number of columns of matrices must match (see arg 2)"

$call
rbind(info, getNamespaceInfo(env, "S3methods"))

[[1]]
[1] "desc"

$message
[1] "package ‘assertthat’ does not have a namespace"

$package
[1] "assertthat"

package.lib [1] "\\\\INFPWFS221.ad.unsw.edu.au/Student046/z5059502/R/win-library/3.5"

$call
NULL

[[1]]
[1] "devtools"

$message
[1] "package ‘cli’ does not have a namespace"

$package
[1] "cli"

package.lib [1] "\\\\INFPWFS221.ad.unsw.edu.au/Student046/z5059502/R/win-library/3.5"

$call
NULL

[[1]]
[1] "ggplot2"

$message
[1] "number of columns of matrices must match (see arg 2)"

$call
rbind(info, getNamespaceInfo(env, "S3methods"))

[[1]]
[1] "ggpubr"

$message
[1] "number of columns of matrices must match (see arg 2)"

$call
rbind(info, getNamespaceInfo(env, "S3methods"))

[[1]]
[1] "gh"

$message
[1] "package ‘jsonlite’ does not have a namespace"

$package
[1] "jsonlite"

package.lib [1] "\\\\INFPWFS221.ad.unsw.edu.au/Student046/z5059502/R/win-library/3.5"

$call
NULL

[[1]]
[1] "jsonlite"

$message
[1] "package ‘jsonlite’ does not have a namespace"

$package
[1] "jsonlite"

package.lib [1] "\\\\INFPWFS221.ad.unsw.edu.au/Student046/z5059502/R/win-library/3.5"

$call
NULL

[[1]]
[1] "pkgbuild"

$message
[1] "package ‘cli’ does not have a namespace"

$package
[1] "cli"

package.lib [1] "\\\\INFPWFS221.ad.unsw.edu.au/Student046/z5059502/R/win-library/3.5"

$call
NULL

[[1]]
[1] "pkgload"

$message
[1] ".onLoad failed in loadNamespace() for 'pkgload', details:\n call: NULL\n error: package ‘assertthat’ does not have a namespace"

$call
NULL

[[1]]
[1] "prettyunits"

$message
[1] "package ‘prettyunits’ does not have a namespace"

$package
[1] "prettyunits"

package.lib [1] "\\\\INFPWFS221.ad.unsw.edu.au/Student046/z5059502/R/win-library/3.5"

$call
NULL

[[1]]
[1] "rcmdcheck"

$message
[1] "package ‘cli’ does not have a namespace"

$package
[1] "cli"

package.lib [1] "\\\\INFPWFS221.ad.unsw.edu.au/Student046/z5059502/R/win-library/3.5"

$call
NULL

[[1]]
[1] "rgdal"

$message
[1] "package ‘rgdal’ does not have a namespace"

$package
[1] "rgdal"

package.lib [1] "\\\\INFPWFS221.ad.unsw.edu.au/Student046/z5059502/R/win-library/3.5"

$call
NULL

[[1]]
[1] "rprojroot"

$message
[1] "package ‘rprojroot’ does not have a namespace"

$package
[1] "rprojroot"

package.lib [1] "\\\\INFPWFS221.ad.unsw.edu.au/Student046/z5059502/R/win-library/3.5"

$call
NULL

[[1]]
[1] "sessioninfo"

$message
[1] "package ‘cli’ does not have a namespace"

$package
[1] "cli"

package.lib [1] "\\\\INFPWFS221.ad.unsw.edu.au/Student046/z5059502/R/win-library/3.5"

$call
NULL

[[1]]
[1] "translations"

$message
[1] "package ‘translations’ does not have a namespace"

$package
[1] "translations"

$package.lib
[1] "C:/Program Files/R/R-3.5.2/library"

$call
NULL

WELL! That's what I call a herd of error messages.

ggplot has both testthat and dplyr among "suggests" as well as others of these failing packages. I'm going to kick this thread to @mara and @jcblum who have the Win experience I lack and have probably seen this before, or something similar. Updating to R 3.6.0 might help if you then run

update.packages()

but I'd put that off, since it takes a while.

1 Like

Just to discard some common issues try updating your packages with checkBuilt, restart your R session and try to load ggplot2 again.

update.packages(checkBuilt=TRUE)

I have done so and have tried to re-install ggplot2. Here is the result :
(NOTE I had to delete a few of the links, as new users can only comments two links per post)

install.packages("ggplot2")
WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding:

https://cran.rstudio.com/bin/windows/Rtools/
Installing package into ‘\INFPWFS221.ad.unsw.edu.au/Student046$/z5059502/R/win-library/3.5’
(as ‘lib’ is unspecified)
also installing the dependencies ‘digest’, ‘tibble’

trying URL 'DELETED'
Content type 'application/zip' length 210846 bytes (205 KB)
downloaded 205 KB

trying URL 'DELETED'
Content type 'application/zip' length 334062 bytes (326 KB)
downloaded 326 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/ggplot2_3.1.1.zip'
Content type 'application/zip' length 3622647 bytes (3.5 MB)
downloaded 3.5 MB

Warning in install.packages :
write error in extracting from zip file
Warning in install.packages :
write error in extracting from zip file
Warning in install.packages :
write error in extracting from zip file
Warning in install.packages :
cannot open compressed file 'ggplot2/DESCRIPTION', probable reason 'No such file or directory'
Error in install.packages : cannot open the connection

library(ggplot2)
package �ggplot2� was built under R version 3.5.3Error: package or namespace load failed for ‘ggplot2’ in rbind(info, getNamespaceInfo(env, "S3methods")):
number of columns of matrices must match (see arg 2)

Are you running RStudio as administrator? have you tried installing system wide instead of in your user library?

Note: To avoid the link limit, post your code between backticks like this

```
https://cran.rstudio.com/bin/windows/Rtools/
Installing package into ‘\INFPWFS221.ad.unsw.edu.au/Student046$/z5059502/R/win-library/3.5’
(as ‘lib’ is unspecified)
also installing the dependencies ‘digest’, ‘tibble’
```

I'm actually not a Windows user, so I'm not sure I can be of much help in that capacity. :grimacing:

I'm with @andresrcs in terms of guessing that there's a permissions issue going on, since there are write errors for seemingly all of the packages.

Ha! You just proved my point :smirk: I have zero memory of Win permissions.

Do you have the latest version of Rtools installed also?
Just a hunch but I remember upgrading to R 3.5 on Windows required me to rebuild several package dependencies during the process of installing a particular package.
If you have Rtools installed, and you have admin rights, you may get prompted to build/rebuild dependencies during the installation.
It might be an iterative process - I remember this particular package took me 4 attempts to get through all the successive failures until the target package eventually installed.

2 Likes

So I have completely uninstalled R 3.5.2 and installed R 3.6.0. I am running RStudio as an administrator.

It seems to be working MUCH better (despite still being run on Windows 7). It has successfully installed ggplot2, When I try to load the packadge, the following comes up:

library(ggplot2)
Registered S3 methods overwritten by 'ggplot2':
method from
[.quosures rlang
c.quosures rlang
print.quosures rlang

But ggplot is able to work regardless and I can generate plots! SO I am not really sure what the underlying issue was, but thank you all for your help!