美文网首页R语言可视化
github的包安装不了怎么办(介绍Y叔的一个神包)?

github的包安装不了怎么办(介绍Y叔的一个神包)?

作者: Kevin_Hhui | 来源:发表于2020-08-28 15:38 被阅读0次

    在使用R语言进行数据分析时,我们时不时需要下载github中的R包,但是相信大家经常会遇到一个问题——总是安装失败。原因大都因为网络原因,但是github的网页总是能够上的,而网页上点击Download ZIP也是可以的。相信这个问题困扰了不少人。我们经常的解决方法是通过码云进行间接下载,然后再从本地安装。确实,问题是解决了,但是步骤繁琐,对于追求高效率的同学来说,这是不可接受的,正巧今天偶尔看到Y叔的一个神包,很好的解决了这个问题。

    废话不多说,开始介绍:

    相关函数存在yulab-smu/yulab.utils包中(https://github.com/YuLab-SMU/yulab.utils)。因为我们还没有装这个包,所以我们先利用码云将yulab.utils包下载下来,接着本地安装。

    yulab.utils包下载
    本地安装

    yulab.utils包顺利安装完成,可以使用Y叔的那两个函数了--install.zip()函数和install_zip_gh()函数

    (一)install.zip()函数
    该函数可以直接根据github下载得到的压缩包,进行解压,编译和安装。你只需要给这个函数一个R压缩包即可。用法也极其简单,就install.zip(“R package.zip”)。
    举例:

    library(yulab.utils) #加载yulab.utils包
    ##需要注意的是工作目录下必须有ggtree.zip文件
    install_zip("ggtree.zip") 
    
    > install_zip("ggtree.zip")
    ✔  checking for file ‘/tmp/RtmpHiXVWl/file3ea34246ccb64/ggtree/DESCRIPTION’ ...
    ─  preparing ‘ggtree’:
    ✔  checking DESCRIPTION meta-information ...
    ─  checking for LF line-endings in source and make files and shell scripts
    ─  checking for empty or unneeded directories
    ─  building ‘ggtree_2.1.6.tar.gz’
       
    Installing package into ‘/home/ygc/R/library’
    (as ‘lib’ is unspecified)
    inferring 'repos = NULL' from 'pkgs'
    * installing *source* package ‘ggtree’ ...
    ** using staged installation
    ** R
    ** inst
    ** byte-compile and prepare package for lazy loading
    ** help
    *** installing help indices
    ** building package indices
    ** installing vignettes
    ** testing if installed package can be loaded from temporary location
    ** testing if installed package can be loaded from final location
    ** testing if installed package keeps a record of temporary installation path
    * DONE (ggtree)
    
    library(ggtree) #查看ggtree是否安装成功
    

    (二)install_zip_gh()函数
    这个函数类似于devtools::install_github(),它可以直接去下载zip包,这样避免无法访问github的问题。下载好zip包后,它再调用install_zip()进行编译安装。

    真的一条命令搞定github R包的安装。

    值得注意的是,install_zip_gh()函数依赖downloader.R,如果有同学发现报错说缺少downloader,则直接利用 install.packages('downloader')就行了。

    library(yulab.utils)
    ##这里拿Y叔的ggtree来演示
    install_zip_gh("yulab-smu/ggtree")
    
    > install_zip_gh("yulab-smu/ggtree")
    trying URL 'https://codeload.github.com/yulab-smu/ggtree/zip/master'
    downloaded 327 KB
    
       checking for file ‘/tmp/RtmpHiXVWl/file3ea34c0f3725/ggtree-master/DESCRIPTION✔  checking for file ‘/tmp/RtmpHiXVWl/file3ea34c0f3725/ggtree-master/DESCRIPTION’
    ─  preparing ‘ggtree’:
    ✔  checking DESCRIPTION meta-information ...
    ─  checking for LF line-endings in source and make files and shell scripts
    ─  checking for empty or unneeded directories
    ─  building ‘ggtree_2.1.6.tar.gz’
       
    Installing package into ‘/home/ygc/R/library’
    (as ‘lib’ is unspecified)
    inferring 'repos = NULL' from 'pkgs'
    * installing *source* package ‘ggtree’ ...
    ** using staged installation
    ** R
    ** inst
    ** byte-compile and prepare package for lazy loading
    ** help
    *** installing help indices
    ** building package indices
    ** installing vignettes
    ** testing if installed package can be loaded from temporary location
    ** testing if installed package can be loaded from final location
    ** testing if installed package keeps a record of temporary installation path
    * DONE (ggtree)
    
    library(ggtree) #查看ggtree是否安装成功
    

    至此,这两个函数介绍完毕,大家以后在下载github的包时,再也不用担心啦。

    Y叔-听说你装不了github的包?

    相关文章

      网友评论

        本文标题:github的包安装不了怎么办(介绍Y叔的一个神包)?

        本文链接:https://www.haomeiwen.com/subject/yrjlsktx.html