1
votes

I've tried to install ggplot2 first with install.packages("ggplot2") but after I try to open with library ("ggplot2") it gives me this error message:

library ('ggplot2')

Error in library("ggplot2") : there is no package called ‘ggplot2’

Is this because I'm trying to run this on a mac or RStudio instead of R? How can I get it installed?

These are the details of the version I'm using:

RStudio Version 0.99.902 – © 2009-2016 RStudio, Inc. Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/604.4.7 (KHTML, like Gecko

Any help would be greatly appreciated!

Here's what I get when I try to install ggplot as a package if it helps...

> install.packages("ggplot2")
Installing package into ‘/Users/crystlewee/Library/R/3.2/library’
(as ‘lib’ is unspecified) also installing the dependency ‘scales’

There are binary versions available but the source versions are later:
  binary source needs_compilation
scales   0.4.0  0.5.0              TRUE
ggplot2  2.1.0  2.2.1             FALSE
Do you want to install from sources the package which needs compilation?
y/n: y
installing the source packages ‘scales’, ‘ggplot2’
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                               Dload  Upload   Total   Spent    Left  Speed
0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0  0 59867    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0100 59867  100 59867    0     0  39753      0  0:00:01  0:00:01 --:--:-- 39752
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                               Dload  Upload   Total   Spent    Left  Speed
0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0 16 
* installing *source* package ‘scales’ ...
** package ‘scales’ successfully unpacked and MD5 sums checked
** libs
llvm-g++-4.2 -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG  -I/usr/local/include -I"/Users/crystlewee/Library/R/3.2/library/Rcpp/include"   -fPIC  -mtune=core2 -g -O2  -c RcppExports.cpp -o RcppExports.o
/bin/sh: llvm-g++-4.2: command not found
make: *** [RcppExports.o] Error 127
ERROR: compilation failed for package ‘scales’
* removing ‘/Users/crystlewee/Library/R/3.2/library/scales’
* restoring previous ‘/Users/crystlewee/Library/R/3.2/library/scales’
Warning in install.packages :
installation of package ‘scales’ had non-zero exit status
* installing *source* package ‘ggplot2’ ...
** package ‘ggplot2’ successfully unpacked and MD5 sums checked
** R
** data
*** moving datasets to lazyload DB
** inst
** preparing package for lazy loading
Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) : 
namespace ‘scales’ 0.4.0 is being loaded, but >= 0.4.1 is required
ERROR: lazy loading failed for package ‘ggplot2’
* removing ‘/Users/crystlewee/Library/R/3.2/library/ggplot2’
Warning in install.packages :
installation of package ‘ggplot2’ had non-zero exit status

The downloaded source packages are in
‘/private/var/folders/my/vqvl_d89237fcc75nv24lqxw0000gn/T/Rtmpv0MgCR/downloaded_packages’
1
I don't know if it matters but both your R and R studio are pretty old. The current versions are respectively 3.4.3 and 1.1.350MLavoie
namespace ‘scales’ 0.4.0 is being loaded, but >= 0.4.1 is required -> github.com/tidyverse/ggplot2/issues/1898CMichael

1 Answers

1
votes

The first error message you have is in compiling scales:

/bin/sh: llvm-g++-4.2: command not found

I don't know much about C++, but g++ is a C++ compiler. ggplot2 depends on scales, and scales depends on Rcpp to interface with C++. Make sure you have Rcpp installed and up to date.

A comment above points out that your version of R is outdated. If possible, I would update R. That might generally solve some of these issues. You're also installing from source—do you have to? Try answering 'no' when prompted about installing the packages from source vs binaries.