在Mac上安装R gsl软件包

Roy*_*lTS 13 macos r gsl

我正在尝试gsl为R 安装软件包,我理解这只是GSL的一个包装,在OSX Mavericks下.我试过了明显的事:

> 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)
Run Code Online (Sandbox Code Playgroud)

所以我跑了

> 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
Run Code Online (Sandbox Code Playgroud)

没有安装GSL.D'哦!所以我通过Homebrew安装GSL:

~  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
Run Code Online (Sandbox Code Playgroud)

尝试再次安装R包:

> 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
Run Code Online (Sandbox Code Playgroud)

我显然是以错误的方式解决这个问题,但我不确定问题究竟在哪里.

And*_*ndy 15

我能够通过手动前缀CFLAGSLDFLAGS来自gsl-config --cflags和的输出gsl-config --libs分别使用标准的Brew安装的R和gsl来实现工作(OS X Yosemite 10.10,R 3.1.1,gsl 1.16,gsl R包1.9-10).

下列:

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

为我工作.

请注意,gsl-config列出了我的酒窖的直接路径,上面的路径是brew符号链接.

  • 嗨,我最初不明白你的解决方案(```,在哪里设置标志等),但终于想通了(我猜):运行`gsl-config --cflags`给出(对我来说10.11) )`-I/usr/local/include`并运行`gsl-config --libs`给`-L/usr/local/lib -lgsl -lgslcblas`.因此,我用`CFLAGS =" - I/usr/local/include"LDFLAGS =" - L/usr/local/lib -lgsl -lgslcblas"R`启动R(来自终端).然后`install.packages("gsl")`有效.认为这可能对其他人(技术不太精通)有所帮助. (6认同)

Roy*_*lTS 6

我终于得到了这个工作,虽然我不确定以下哪些部分是绝对必要的.这是一个逐步的说明列表:

(括号中的步骤可能是可选的.也许整个事情适用于自制软件)

  1. (从http://ftp.gnu.org/gnu/gsl/下载最新版本的GSL (截至撰写文件时,获取的是gsl-1.16.tar.gz))
  2. (打开一个终端窗口,解压缩文件,cd进入目录然后运行./configure,make然后make install)
  3. http://cran.r-project.org/web/packages/gsl/index.html下载源代码到R包
  4. 打开一个终端窗口然后运行 launchctl setenv PATH "/usr/local/bin:$PATH"
  5. 在同一个终端窗口中,通过解压缩刚刚下载的文件,cd进入目录然后运行R CMD build ./gsl并构建R包(我无法从R中工作)R CMD INSTALL gsl_1.9-10.tar.gz


小智 5

对于Mac,只需运行:

brew install gsl
Run Code Online (Sandbox Code Playgroud)

然后将软件包安装在r中

  • 这个答案应该被接受!@RoyalTS (2认同)