本文記錄的是linux下R安裝的心得械媒,windows下的安裝方法請(qǐng)自行g(shù)oogle:
先說(shuō)有root權(quán)限的時(shí)候:
官網(wǎng)上下載R源碼:找到latest release 版本:R-3.5.1.tar.gz
https://mirrors.tuna.tsinghua.edu.cn/CRAN/
解壓胸遇,進(jìn)入路徑
tar -zxvf R-3.5.1.tar.gz
cd R-3.5.1
./configure
有報(bào)錯(cuò):
configure: error: --with-readline=yes (default) and headers/libs are not available
設(shè)置如下參數(shù): ./configure --with-readline=no
或者centos系統(tǒng):安裝readline:yum install readline-devel
或者ubuntu系統(tǒng):安裝readline:
安裝成功后繼續(xù)./configure
又出現(xiàn)報(bào)錯(cuò):
configure: error: --with-x=yes (default) and X11 headers/libs are not available
設(shè)置參數(shù) --with-x=no
或者安裝x:
yum install libX11-devel
yum install libXt-devel
繼續(xù)
./configure --with-readline=no --with-x=no
還報(bào)錯(cuò):沒(méi)有裝libzma
configure: error: "liblzma library and headers are required"
解決方法:
wget https://tukaani.org/xz/xz-5.2.4.tar.gz
tar -zxvf xz-5.2.4.tar.gz
cd xz-5.2.4/
./configure
make
make install
安裝完成xz,無(wú)報(bào)錯(cuò)读拆,再來(lái)繼續(xù)編譯R
./configure --with-readline=no --with-x=no
又報(bào)錯(cuò):沒(méi)有pcre
checking whether PCRE support suffices... configure: error: pcre >= 8.20 library and headers are required
解決方法:
wget https://nchc.dl.sourceforge.net/project/pcre/pcre/8.42/pcre-8.42.tar.gz
tar -zxvf pcre-8.42.tar.gz
cd pcre-8.42.tar.gz
./configure
make
make install
安裝完成pcre擅憔,無(wú)報(bào)錯(cuò),再來(lái)繼續(xù)編譯R
./configure --with-readline=no --with-x=no
又報(bào)錯(cuò):沒(méi)有l(wèi)ibcurl
configure: error: libcurl >= 7.22.0 library and headers are required with support for https
解決方法:
wget https://curl.haxx.se/download/curl-7.61.0.tar.gz
tar -zxvf curl-7.61.0.tar.gz
cd curl-7.61.0/
./configure
make
make install
安裝完成curl檐晕,無(wú)報(bào)錯(cuò),再來(lái)繼續(xù)編譯R
./configure --with-readline=no --with-x=no
又報(bào)錯(cuò):
configure: error: libcurl >= 7.22.0 library and headers are required with support for https
好像上一步的libcurl沒(méi)有安裝成功吶暑诸?奇怪,
仔細(xì)觀察了一下辟灰,發(fā)現(xiàn)雖然是以root下載的个榕,但是解壓后的目錄是以用戶擁有的方式,于是
用sudo的方式試一次:
sudo ./configure
make
make install
安裝完成芥喇,無(wú)報(bào)錯(cuò)
再來(lái)安裝R
./configure --with-readline=no --with-x=no
報(bào)錯(cuò):
configure: error: libcurl >= 7.22.0 library and headers are required with support for https
還是這個(gè)錯(cuò)西采。。继控。械馆。。
已奔潰武通。霹崎。。
$ curl -V
curl 7.60.0 (x86_64-conda_cos6-linux-gnu) libcurl/7.60.0 OpenSSL/1.0.2o zlib/1.2.11
Release-Date: 2018-05-16
Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP UnixSockets HTTPS-proxy
看版本冶忱,已經(jīng)是7.60了呀仿畸。
有人說(shuō)要下載libcurl-devel,
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/libcurl-devel-7.29.0-46.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/libcurl-7.29.0-46.el7.x86_64.rpm
rpm -ivh libcurl-devel-7.29.0-46.el7.x86_64.rpm libcurl-7.29.0-46.el7.x86_64.rpm
試了還是不行朗和,最后错沽。。眶拉。
用別的用戶名登錄千埃,不用root登錄
./configure --with-readline=no --with-x=no
···
R is now configured for x86_64-pc-linux-gnu
Source directory: .
Installation directory: /usr/local
C compiler: gcc -std=gnu99 -g -O2
Fortran 77 compiler: gfortran -g -O2
Default C++ compiler: g++ -g -O2
C++98 compiler: g++ -std=gnu++98 -g -O2
C++11 compiler: g++ -std=gnu++11 -g -O2
C++14 compiler:
C++17 compiler:
Fortran 90/95 compiler: gfortran -g -O2
Obj-C compiler:
Interfaces supported:
External libraries: readline, curl
Additional capabilities: NLS
Options enabled: shared BLAS, R profiling
Capabilities skipped: PNG, JPEG, TIFF, cairo, ICU
Options not enabled: memory profiling
Recommended packages: yes
configure: WARNING: you cannot build info or HTML versions of the R manuals
configure: WARNING: you cannot build PDF versions of the R manuals
configure: WARNING: you cannot build PDF versions of vignettes and help pages
最后只有三個(gè)無(wú)關(guān)緊要的提醒。
趕緊
sudo make
輸入了密碼
sudo make install
成功了 但是使用時(shí)還是沒(méi)有有問(wèn)題忆植,沒(méi)有l(wèi)ibR.so放可?谒臼?
當(dāng)沒(méi)有安裝bzip2時(shí)會(huì)報(bào)錯(cuò)如下:
checking whether bzip2 support suffices... configure: error: bzip2 library and headers are required
最后。耀里。蜈缤。
一怒之下刪掉了安裝了所有版本R,
rm -rf /usr/bin/R*
rm -rf /usr/local/bin/R*
刪掉了安裝的所有bzip2,
rm -rf /usr/local/bin/bz*
rm -rf /usr/local/include/bz*
yum remove bzip2
重新解壓 bzip2
tar -zxvf bzip2-1.0.6.tar.gz
cd bzip2-1.0.6
make -f Makefile-libbz2_so
修改Makefile其中兩行冯挎。
vi Makefile
CC=gcc -fPIC
CFLAGS=-Wall -fPIC -Winline -O2 -g $(BIGFILES)
然后
make
make install
然后安裝R
將原來(lái)R解壓的路徑也刪掉了
重新解壓R包
tar -zxvf R-3.5.1.tar.gz
cd R-3.5.1
./configure --enable-R-shlib
居然沒(méi)有報(bào)錯(cuò)
make
make install
都沒(méi)有報(bào)錯(cuò)底哥。。房官。趾徽。。翰守。
重點(diǎn)來(lái)了
將R安裝到指定路徑下:在沒(méi)有root權(quán)限時(shí)孵奶,我們只能安裝在指定目錄下。
要想安裝到指定目錄中則需要指定: --prefix=/path/to/install/
./configure --enable-R-shlib
,先根據(jù)報(bào)錯(cuò)將依賴的各種庫(kù)都裝上蜡峰。安裝時(shí)也要指定路徑了袁,一般情況下我會(huì)將其安裝在解壓后的該目錄。
先后安裝了zlib湿颅,bzip2,xz,curl.
然后編譯的時(shí)候要加上LDFLAGS和CPPFLAGS相關(guān)的路徑:
./configure --prefix=$HOME/Programme/R-3.3.1 --enable-R-shlib LDFLAGS="-L/$HOME/Programme/zlib-1.2.11/lib -L/$HOME/Programme/bzip2-1.0.6/lib -L/$HOME/Programme/xz-5.2.3/lib -L/$HOME/Programme/pcre-8.40/lib -L/$HOME/Programme/curl-7.52.1/lib" CPPFLAGS="-I/$HOME/Programme/zlib-1.2.11/include -I/$HOME/Programme/bzip2-1.0.6/include -I/$HOME/Programme/xz-5.2.3/include -I/$HOME/Programme/pcre-8.40/include -I/$HOME/Programme/curl-7.52.1/include"
然而還是會(huì)報(bào)錯(cuò):
報(bào)錯(cuò):
/usr/bin/ld: warning: libpcre.so.1, needed by ../../lib/libR.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: liblzma.so.5, needed by ../../lib/libR.so, not found (try using -rpath or -rpath-link)
../../lib/libR.so: undefined reference to `pcre_fullinfo'
../../lib/libR.so: undefined reference to `lzma_lzma_preset@XZ_5.0'
../../lib/libR.so: undefined reference to `lzma_alone_decoder@XZ_5.0'
../../lib/libR.so: undefined reference to `lzma_crc64@XZ_5.0'
../../lib/libR.so: undefined reference to `lzma_raw_encoder@XZ_5.0'
../../lib/libR.so: undefined reference to `pcre_config'
../../lib/libR.so: undefined reference to `lzma_code@XZ_5.0'
../../lib/libR.so: undefined reference to `lzma_stream_decoder@XZ_5.0'
../../lib/libR.so: undefined reference to `pcre_free'
../../lib/libR.so: undefined reference to `lzma_raw_decoder@XZ_5.0'
../../lib/libR.so: undefined reference to `pcre_free_study'
../../lib/libR.so: undefined reference to `pcre_assign_jit_stack'
../../lib/libR.so: undefined reference to `pcre_exec'
../../lib/libR.so: undefined reference to `lzma_version_string@XZ_5.0'
../../lib/libR.so: undefined reference to `pcre_maketables'
../../lib/libR.so: undefined reference to `lzma_stream_encoder@XZ_5.0'
../../lib/libR.so: undefined reference to `pcre_compile'
../../lib/libR.so: undefined reference to `pcre_study'
../../lib/libR.so: undefined reference to `pcre_version'
../../lib/libR.so: undefined reference to `lzma_end@XZ_5.0'
../../lib/libR.so: undefined reference to `pcre_jit_stack_alloc'
collect2: error: ld returned 1 exit status
make[3]: *** [R.bin] Error 1
make[3]: Leaving directory `/builder/software/R/src/main'
make[2]: *** [R] Error 2
make[2]: Leaving directory `/builder/software/R/src/main'
make[1]: *** [R] Error 1
make[1]: Leaving directory `/builder/software/R/src'
make: *** [R] Error 1
重點(diǎn)來(lái)了:
/usr/bin/ld: warning: libpcre.so.1, needed by ../../lib/libR.so, not found (try using -rpath or -rpath-link)
怎么會(huì)有這樣的報(bào)錯(cuò)载绿?編譯的時(shí)候不是已經(jīng)將這兩個(gè)庫(kù)的路徑傳入了呀?
一番搜索后肖爵,
有人提出
要添加動(dòng)態(tài)庫(kù)
#cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
/opt/pcre-8.39/lib
/opt/xz-5.2.2/lib
然后執(zhí)行
#ldconfig
但是我沒(méi)有root權(quán)限啊,于是再一帆研究臀脏,根據(jù)報(bào)錯(cuò)提示劝堪,設(shè)置一下-rpath
看行不行。
修改Makeconf文件揉稚,再LDFLAGS這里加上了-Wl,-rpath
后面跟這兩個(gè)庫(kù)的路徑秒啦,
LDFLAGS = -L/BIGDATA1/cygene_sydu_1/02.dropEst/zlib-1.2.11/lib -L/BIGDATA1/cygene_sydu_1/02.dropEst/bzip2-1.0.6/lib -L/BIGDATA1/cygene_sydu_1/02.dropEst/xz-5.2.4/lib -L/BIGDATA1/cygene_sydu_1/02.dropEst/pcre-8.42/lib -L/BIGDATA1/cygene_sydu_1/02.dropEst/curl-7.61.0/lib -Wl,-rpath=/BIGDATA1/cygene_sydu_1/02.dropEst/pcre-8.42/lib -Wl,-rpath=/BIGDATA1/cygene_sydu_1/02.dropEst/xz-5.2.4/lib
再進(jìn)行make
,make install
就不會(huì)報(bào)錯(cuò),完成安裝搀玖。
或者在編譯的時(shí)候直接將-Wl,-rpath=/
的路徑跟在LDFLAGS里面余境,要寫(xiě)兩次哦。
補(bǔ)充:
如果遇到如下報(bào)錯(cuò)
begin installing recommended package Matrix
ERROR: failed to lock directory ‘/BIGDATA1/cygene_sydu_1/software/R-3.5.1/library’ for modifying
Try removing ‘/BIGDATA1/cygene_sydu_1/software/R-3.5.1/library/00LOCK-Matrix’
make[2]: *** [Matrix.ts] Error 1
make[2]: Leaving directory `/BIGDATA1/cygene_sydu_1/software/R-3.5.1/src/library/Recommended'
make[1]: *** [recommended-packages] Error 2
make[1]: Leaving directory `/BIGDATA1/cygene_sydu_1/software/R-3.5.1/src/library/Recommended'
make: *** [stamp-recommended] Error 2
這里是開(kāi)始安裝某個(gè)package時(shí)失敗了灌诅,那么想讓它跳過(guò)芳来,不安裝就好了,在提示的報(bào)錯(cuò)信息中找到安裝該package的路徑猜拾,把里面的相應(yīng)的package刪掉即可即舌,我這里刪掉了Martrix包;
rm /BIGDATA1/cygene_sydu_1/software/R-3.5.1/src/library/Recommended/Matrix*
等R安裝成功后再手動(dòng)將這些包裝上挎袜。
R 包的安裝
R的package安裝時(shí)遇到錯(cuò)誤可以換鏡像路徑顽聂,舉例如下:
install.packages("Rcpp",dependencies=TRUE, repos='http://cran.rstudio.com/')
install.packages("ggplot2",dependencies=TRUE, repos='http://cran.rstudio.com/')
R ggforce 包安裝
install.packages("ggforce")
library(ggforce)
# geom_circle() 是來(lái)自ggforce這個(gè)包肥惭。用法跟ggplot一樣:
ggplot(df.venn, aes(x0=x, y0=y, r= 1.5, fill = labels)) +
geom_circle(alpha=.3, size=1, colour='grey') +
coord_fixed() + theme_void()
關(guān)于bioconductor
R limma 包安裝
source("http://www.bioconductor.org/biocLite.R")
biocLite("limma")
library(limma)
R tidyverse包安裝
source("http://www.bioconductor.org/biocLite.R")
biocLite("tidyverse")
library(tidyverse)
其他包安裝
source("[http://bioconductor.org/biocLite.R](http://bioconductor.org/biocLite.R)")
biocLite("ALL") 安裝 ALL
biocLite("hgu95av2.db")
library(ALL)
library(hgu95av2.db)
總結(jié):
Ubuntu下基本上可以通過(guò)安裝這些庫(kù)解決:
sudo apt-get install build-essential
sudo apt-get install fort77 (error)
sudo apt-get install xorg-dev
sudo apt-get install liblzma-dev libblas-dev gfortran
sudo apt-get install gcc-multilib
sudo apt-get install gobjc++ (error)
sudo apt-get install aptitude
sudo apt-get install libreadline-dev