國內(nèi)設置清華鏡像
options("repos" = c(CRAN="https://mirrors.tuna.tsinghua.edu.cn/CRAN/"))
1.第一種方法: 直接下載安裝
install.packages('IRkernel',repos = "https://mirrors.tuna.tsinghua.edu.cn/CRAN/")
- 第二種方法:本地安裝
# 先下載資源包 *tar.gz文件
install.packages("path/*tar.gz",repos=NULL,type = 'source')
- 第三種方法:使用devtools從github安裝
# 先安裝devtools
# install.packages("devtools")
devtools::install_github("tidyverse/ggplot2")
4.第四種方法:使用conda安裝,一般難裝的包都可以搞定,不過版本通常較舊
conda install -c r r-ggplot2
- R包安裝技巧 : 當R包裝不上時,直接在conda 環(huán)境下安裝,move 至 Lib即可解決;
如果遇到lib依賴, 找到虛擬環(huán)境下的lib庫, 將提示的.lib.so文件直接復制或者軟鏈接
# 查看R lib位置
.libpaths()
ln -s ~/miniconda3/envs/py38/lib/libstdc++.so.6 libstdc++.so.
- 安裝 github上的包遇到網(wǎng)絡問題時如何解決?
直接將文件下載至本地,devtools安裝
devtools::install_local(path = 'CellChat-master/')
- R版本更新時,R包批量更新方法
# 批量更新
### 新建 R4.2 lib
# eg
dir.create("/R/x86_64-pc-linux-gnu-library/4.2")
.libPaths(c("R/x86_64-pc-linux-gnu-library/4.2","/home/opt/R/4.2.0/lib/R/library"))
### list all packages in R3.6 and update
# eg
reqPkg = list.files(path = .libPaths("/R/x86_64-pc-linux-gnu-library/3.6"))
newPkg = reqPkg[!(reqPkg %in% installed.packages()[,"Package"])]
if(length(newPkg)){install.packages(newPkg)}
- 終極解決方案: 使用conda創(chuàng)建新的R版本虛擬環(huán)境,安裝相應的R包后,使用jupyter notebook調(diào)用R內(nèi)核進行數(shù)據(jù)分析
# 如conda 安裝新的R版本
conda create -n myenvR4.2 r-base=4.2.0 -y
conda activate myenvR4.2
R
install.packages('Seurat',repos = "https://mirrors.tuna.tsinghua.edu.cn/CRAN/")
#然后為 Jupyter安裝R內(nèi)核
# step1.首先使用conda創(chuàng)建需要的R虛擬環(huán)境,如R3.6
conda create -n myEnvR r=3.6.0 -y
install.packages('IRkernel')
#可以直接安裝在當前用戶中:
IRkernel::installspec()
# 后續(xù)就是jupyter配置,打開就能調(diào)用新的R環(huán)境