Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

installing R gsl package on Mac

Tags:

macos

r

gsl

I'm trying to install the gsl package for R, which I understand is simply a wrapper around the GSL, under OSX Mavericks. I've tried the obvious:

> install.packages('gsl')
Installing package into ‘/Users/myusername/Library/R/3.1/library’
(as ‘lib’ is unspecified)

   package ‘gsl’ is available as a source package but not as a binary

Warning in install.packages :
  package ‘gsl’ is not available (for R version 3.1.0)

So I ran

> install.packages('gsl',type = 'source')
Installing package into ‘/Users/myusername/Library/R/3.1/library’
(as ‘lib’ is unspecified)
trying URL 'http://cran.rstudio.com/src/contrib/gsl_1.9-10.tar.gz'
Content type 'application/x-gzip' length 342803 bytes (334 Kb)
opened URL
==================================================
downloaded 334 Kb

* installing *source* package ‘gsl’ ...
** package ‘gsl’ successfully unpacked and MD5 sums checked
checking for gsl-config... no
configure: error: gsl-config not found, is GSL installed?
ERROR: configuration failed for package ‘gsl’
* removing ‘/Users/myusername/Library/R/3.1/library/gsl’
Warning in install.packages :
  installation of package ‘gsl’ had non-zero exit status

No GSL install. D'oh! So I install GSL via Homebrew:

~  brew install gsl
==> Downloading http://ftpmirror.gnu.org/gsl/gsl-1.15.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/gsl/1.15
==> make
==> make install
  /usr/local/Cellar/gsl/1.15: 239 files, 6.7M, built in 101 seconds

Try to install the R package again:

> install.packages('gsl',type = 'source')
Installing package into ‘/Users/myusername/Library/R/3.1/library’
(as ‘lib’ is unspecified)
trying URL 'http://cran.rstudio.com/src/contrib/gsl_1.9-10.tar.gz'
Content type 'application/x-gzip' length 342803 bytes (334 Kb)
opened URL
==================================================
downloaded 334 Kb

* installing *source* package ‘gsl’ ...
** package ‘gsl’ successfully unpacked and MD5 sums checked
checking for gsl-config... /usr/local/bin/gsl-config
checking if GSL version >= 1.12... checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
configure: error: Need GSL version >= 1.12
ERROR: configuration failed for package ‘gsl’
* removing ‘/Users/myusername/Library/R/3.1/library/gsl’
Warning in install.packages :
  installation of package ‘gsl’ had non-zero exit status

I'm obviously going about this the wrong way but am unsure about where exactly the problem lies.

like image 650
RoyalTS Avatar asked Jul 16 '14 12:07

RoyalTS


People also ask

How do I install R packages on Mac?

(If R is not installed, then follow these directions to install R for Mac OS.) Select the Packages & Data menu and Packages Installer submenu item. In the dialog box, click Get List to compile a current list of available packages. Select the packages to install (use the <command> key to select multiple packages).

How do I install a downloaded package in R?

Go into R, click on Packages (at the top of the R console), then click on "Install package(s) from local zip files", then find the zip file with arm from wherever you just saved it. Do the same thing to install each of the other packages you want to install.


3 Answers

I was able to get things working (OS X Yosemite 10.10, R 3.1.1, gsl 1.16, gsl R package 1.9-10) with standard brew-installed R and gsl by manually prefixing CFLAGS and LDFLAGS with the output from gsl-config --cflags and gsl-config --libs respectively.

The following:

CFLAGS="-I/usr/local/opt/gsl/include" LDFLAGS="-L/usr/local/opt/gsl/lib -lgsl -lgslcblas" R
...
> install.packages("gsl")

worked for me.

Note that gsl-config lists the direct path to my Cellar, the paths above are brew symlinks.

like image 53
Andy Avatar answered Oct 26 '22 22:10

Andy


For Mac, just run:

brew install gsl

then install the package in r

like image 20
jackexu Avatar answered Oct 26 '22 23:10

jackexu


I finally got this to work though I'm not sure which parts of the following are absolutely essential. Here's a step-by-step list of instructions:

(steps in parentheses may be optional. Perhaps the whole thing works with homebrew)

  1. (download the latest version of the GSL from http://ftp.gnu.org/gnu/gsl/ (as of this writing the file to get is gsl-1.16.tar.gz))
  2. (open up a terminal window, untar the file, cd into the directory and then run ./configure, make and make install)
  3. download the sources to the R package from http://cran.r-project.org/web/packages/gsl/index.html
  4. open up a terminal window and run launchctl setenv PATH "/usr/local/bin:$PATH"
  5. in the same terminal window, build the R package (I couldn't get this to work from within R) by untar'ing the file just downloaded, cding into the directory and then running R CMD build ./gsl and R CMD INSTALL gsl_1.9-10.tar.gz
like image 40
RoyalTS Avatar answered Oct 27 '22 00:10

RoyalTS