最近在我的授课电脑上面一股脑更新了全部的R套件,包括R和rstudio,以及rtools,还有几百个r包文件夹都删除了。
但是在参考我两年前的教程:一口气安装800个R包,批量安装800多个R包的时候,发现下面的这些包其实是在github上面:
ConsensusTME DoubletFinder EPIC MCPcounter SCENIC SCEVAN SCopeLoomR VISION copykat cpbnplot depmap ggforestplot immunedeconv jjAnno mMCPcounter presto scMetabolism spatstat.core tgutil xCell yaGST
本来应该是使用 devtools::install_github(‘satijalab/seurat-data’) 这样的代码进行安装,但是我因为电脑在长城内部,所以没办法访问github,会得到如下所示的报错:
> devtools::install_github('satijalab/seurat-data')
Downloading GitHub repo satijalab/seurat-data@HEAD
Error: Failed to install 'SeuratData' from GitHub:
error reading from connection
所以就查询了一下他们的github链接,也是很容易构造,一个简单的案例是:
https://api.github.com/repos/satijalab/seurat-data/tarball/HEAD
最后全部的列表如下所示:
https://api.github.com/repos/cansysbio/ConsensusTME/tarball/HEAD
https://api.github.com/repos/chris-mcginnis-ucsf/DoubletFinder/tarball/HEAD
https://api.github.com/repos/GfellerLab/EPIC/tarball/HEAD
https://api.github.com/repos/ebecht/MCPcounter/tarball/master
https://api.github.com/repos/aertslab/SCENIC/tarball/HEAD
https://api.github.com/repos/AntonioDeFalco/SCEVAN/tarball/HEAD
https://api.github.com/repos/aertslab/SCopeLoomR/tarball/HEAD
https://api.github.com/repos/YosefLab/VISION/tarball/HEAD
https://api.github.com/repos/navinlabcode/copykat/tarball/HEAD
https://api.github.com/repos/noriakis/cpbnplot/tarball/HEAD
https://api.github.com/repos/nightingalehealth/ggforestplot/tarball/HEAD
https://api.github.com/repos/omnideconv/immunedeconv/tarball/HEAD
https://api.github.com/repos/junjunlab/jjAnno/tarball/HEAD
https://api.github.com/repos/cit-bioinfo/mMCP-counter/tarball/HEAD
https://api.github.com/repos/immunogenomics/presto/tarball/HEAD
https://api.github.com/repos/wu-yc/scMetabolism/tarball/HEAD
https://api.github.com/repos/spatstat/spatstat.core/tarball/HEAD
https://api.github.com/repos/tanaylab/tgutil/tarball/HEAD
https://api.github.com/repos/dviraran/xCell/tarball/HEAD
上面的链接每个背后都是一个文件,需要自己手动点击下载,得到如下所示的文件:
$ ls -lht |cut -d" " -f 5-
86M Sep 19 10:19 omnideconv-immunedeconv-v2.1.2-0-g0c5c619.tar.gz
19M Sep 19 10:19 dviraran-xCell-1.3-2-g7339410.tar.gz
1.3M Sep 19 10:19 spatstat-spatstat.core-v2.4-3-19-g6c80ceb.tar.gz
28K Sep 19 10:19 tanaylab-tgutil-0.1.4-61-g0e4a2e8.tar.gz
770K Sep 19 10:19 wu-yc-scMetabolism-4f6f8f1.tar.gz
663K Sep 19 10:19 immunogenomics-presto-31dc97f.tar.gz
19K Sep 19 10:19 cit-bioinfo-mMCP-counter-v1.1.0-3-gcec6971.tar.gz
1.5M Sep 19 10:19 junjunlab-jjAnno-0.0.3-13-ge8de4ce.tar.gz
15M Sep 19 10:19 NightingaleHealth-ggforestplot-547617e.tar.gz
6.9M Sep 19 10:19 navinlabcode-copykat-b795ff7.tar.gz
574K Sep 19 10:19 noriakis-cpbnplot-f279229.tar.gz
27M Sep 19 10:19 YosefLab-VISION-v3.0.1-0-g8dc5c4e.tar.gz
6.6M Sep 19 10:19 AntonioDeFalco-SCEVAN-1.0.0-32-g8048b45.tar.gz
15M Sep 19 10:19 aertslab-SCENIC-v1.3.0-1-g06d3f34.tar.gz
587K Sep 19 10:19 aertslab-SCopeLoomR-v0.3.1-83-g20f4e0a.tar.gz
4.5M Sep 19 10:19 GfellerLab-EPIC-v1.1.7-0-g50a4f40.tar.gz
93K Sep 19 10:19 ebecht-MCPcounter-b6eac73.tar.gz
1.4M Sep 19 10:19 chris-mcginnis-ucsf-DoubletFinder-1b1d4e2.tar.gz
766K Sep 19 10:19 cansysbio-ConsensusTME-b3c8d3a.tar.gz
19M Sep 18 11:48 genecell-COSGR-v0.9.0-1-gc8f3f53.tar.gz
36M Sep 18 10:27 zhanghao-njmu-SCP-v0.5.1-0-g458ce17.tar.gz
这样的github包的安装方法也是有两个:
## 使用devtools::install_local自动安装SCP及相关依赖(这种安装过程可以自动寻找安装依赖包):
devtools::install_local("SCP-0.5.1.tar.gz")
### 或使用install.packages安装SCP(如果缺失依赖包会报错,需要再根据提示手动逐一安装依赖包):
install.packages("SCP-0.5.1.tar.gz", repos = NULL, type = "source")
这里,我们建议是使用 devtools::install_local 安装这一系列包,但是我批量安装的代码没有写好:
fs=list.files(pattern = '*tar.gz')
fs
lapply(fs,function(i){
#i=fs[17]
print(i)
if(i %in% installed.packages()[,"Package"] ){
print('ok')
}else{
print('error')
#devtools::install_local(i, upgrade = c( "never"))
}
})
因为上面的文件名字太长了,而且文件名的规则有点乱,需要从里面切割出来我们的包的名字,有点难度哦!但是之前看到的另外一系列本地包就很容易切割,详见:听说你无法下载SeuratData的单细胞示例数据 :
fs=list.files(pattern = '*tar.gz')
fs
library(devtools)
library(stringr)
lapply(fs,function(i){
#i=fs[17]
print(i)
if(strsplit(i,'_')[[1]][1] %in% installed.packages()[,"Package"] ){
print('ok')
}else{
print('error')
devtools::install_local(i, upgrade = c( "never"))
}
})