美文网首页R语言
R devtools安装yyplot(解决了mac安装错误问题)

R devtools安装yyplot(解决了mac安装错误问题)

作者: RachaelRiggs | 来源:发表于2020-03-14 20:47 被阅读0次

    R version 3.6.0
    重点在4.yyplot安装

    1.设置默认的国内镜像地址

    https://mirrors.tuna.tsinghua.edu.cn/CRAN/中添加
    原则就是越近越好

    image.png

    2.安装devtools(支持从github上下载开源的包)

    install.packages("devtools")
    library(devtools) #先library以后才能用devtools!!
    install_github("GuangchuangYu/yyplot")
    

    结果报错,显示

    ERROR: dependency ‘ggtree’ is not available for package ‘gglayer’
    * removing ‘/Library/Frameworks/R.framework/Versions/3.6/Resources/library/gglayer’
    错误: Failed to install 'yyplot' from GitHub:
      Failed to install 'gglayer' from GitHub:
      (由警告转换成)installation of package ‘/var/folders/rr/3hs35sxn0lsfwvx91_w0vfhr0000gn/T//RtmptB3H8r/file170cd22121a08/gglayer_0.0.1.tar.gz’ had non-zero exit status
    

    仔细看错误提示:dependency ‘ggtree’ is not available for package ‘gglayer’

    于是直接到github上搜Y叔(yuguangchang)的ggtree,因为先下载ggtree才能下gglayer

    结果没搜到Y叔的ggtree,只搜到gglayer
    https://github.com/GuangchuangYu/gglayer

    直接把gglayer改成ggtree,成功跳转到Y叔的ggtree
    https://github.com/YuLab-SMU/ggtree

    image.png

    各种尝试后推荐方法三,因为方法一二理论可行,但是实际操作过程中外网速度太慢容易导致下载失败

    方法一:

    命令:

    devtools::install_git("url")
    

    直接克隆github ggtree的地址,下载ggtree


    image.png

    在Rstudio中输入命令devtools::install_git("url"),一定记得url上有“ ”,不然会提示

    devtools::install_git(https://github.com/YuLab-SMU/ggtree.git)
    错误: 意外的'/' in "devtools::install_git(https:/"
    

    devtools::install_git("https://github.com/YuLab-SMU/ggtree.git")

    方法二:

    命令:

    devtools::install_github("author/packagesname")
    

    "author/packagesname"在url上直接复制即可
    or:

    library(devtools)
    install_github("GuangchuangYu/yyplot")
    
    image.png

    方法三-biomanager安装ggtree(R>=3.5)-推荐

    biomanager的安装见下方3.

    去官网找安装代码
    http://bioconductor.org/packages/release/bioc/html/ggtree.html

    if (!requireNamespace("BiocManager", quietly = TRUE))
      install.packages("BiocManager")
    
    BiocManager::install("ggtree")
    
    image.png

    wow!安装成功!并提示是否更新相关的包

    image.png

    3.安装biomanager (好处是每半年会对R包upgrade&debug)

    Bioconductor在R3.5版本以后,终于放弃了source() 这种危险的链接方式,改为用新的安装方式BiocManager进行安装:

    对于R 3.5 以下的版本,依旧需要使用BiocLite:

    代码已经给好,不再需要source():

    去官网https://bioconductor.org/install/上查R对应的安装命令,例如我的是R 3.6,对应bioconductor 3.10

    image.png
    >if (!requireNamespace("BiocManager", quietly = TRUE))
          install.packages("BiocManager")
    BiocManager::install(version = "3.10")
    
    Bioconductor version 3.10 (BiocManager 1.30.10),
      R 3.6.2 (2019-12-12)
    Installing package(s) 'BiocVersion'
    试开URL’https://bioconductor.org/packages/3.10/bioc/bin/macosx/el-capitan/contrib/3.6/BiocVersion_3.10.1.tgz'
    Content type 'application/x-gzip' length 5574 bytes
    ==================================================
    downloaded 5574 bytes
    
    
    The downloaded binary packages are in
        /var/folders/rr/3hs35sxn0lsfwvx91_w0vfhr0000gn/T//RtmpH6X08I/downloaded_packages
    

    Bioconductor的 bioc-devel 每六个月(其实是每年四月和十月)会对旗下的生物相关的R包进行更新和debug,install.packages在很多时候检测不到这些更新,导致使用者总是安装过时的版本

    4.安装yyplot-重点

    > install_github("GuangchuangYu/yyplot")
    
    >install_github("GuangchuangYu/yyplot")
    Downloading GitHub repo GuangchuangYu/yyplot@master
    Downloading GitHub repo GuangchuangYu/gglayer@master
    Skipping 1 packages not available: ggtree
    The downloaded binary packages are in
        /var/folders/rr/3hs35sxn0lsfwvx91_w0vfhr0000gn/T//RtmpH6X08I/downloaded_packages
    错误: Failed to install 'unknown package' from GitHub:
      Failed to install 'gglayer' from GitHub:
      Failed to connect to api.github.com port 443: Connection refused
    

    报错:
    错误: Failed to install 'unknown package' from GitHub: Failed to install 'gglayer' from GitHub: Failed to connect to api.github.com port 443: Connection refused

    于是单独安装gglayer,先用的biomanager

    > BiocManager::install("gglayer")
    Bioconductor version 3.10 (BiocManager 1.30.10),
      R 3.6.2 (2019-12-12)
    Installing package(s) 'gglayer'
    Warning message:
    package ‘gglayer’ is not available (for R version 3.6.2) 
    

    结果显示package ‘gglayer’ is not available (for R version 3.6.2)

    R3.6不能安装gglayer?于是跑到Y叔的github上看支持的R版本,明明支持R>=3.5呀!!


    image.png

    于是重新用devtools安装

    > devtools::install_github("GuangchuangYu/gglayer")
    错误: Failed to install 'gglayer' from GitHub:
      Failed to connect to api.github.com port 443: Connection refused
    

    网络问题?于是设置了代理

    git config --global http.proxy http://144.4X.1X.1X:443
    
    

    再次用devtools安装...

    > devtools::install_github("GuangchuangYu/gglayer")
    Skipping install of 'gglayer' from a github remote, the SHA1 (aa7dab85) has not changed since last install.
      Use `force = TRUE` to force installation
    

    按照提示来

    > devtools::install_github("GuangchuangYu/gglayer",force = TRUE)
    
    > devtools::install_github("GuangchuangYu/gglayer",force = TRUE)
    Downloading GitHub repo GuangchuangYu/gglayer@master
    Skipping 1 packages not available: ggtree
    ✓  checking for file ‘/private/var/folders/rr/3hs35sxn0lsfwvx91_w0vfhr0000gn/T/RtmpH6X08I/remotes1737714e28d74/GuangchuangYu-gglayer-aa7dab8/DESCRIPTION’ ...
    ─  preparing ‘gglayer’:
    ✓  checking DESCRIPTION meta-information ...
    ─  checking for LF line-endings in source and make files and shell scripts
    ─  checking for empty or unneeded directories
    ─  building ‘gglayer_0.0.1.tar.gz’
       
    * installing *source* package ‘gglayer’ ...
    ** using staged installation
    ** R
    ** byte-compile and prepare package for lazy loading
    ** help
    *** installing help indices
    ** building package indices
    ** testing if installed package can be loaded from temporary location
    ** testing if installed package can be loaded from final location
    Registered S3 method overwritten by 'treeio':
      method     from
      root.phylo ape 
    ** testing if installed package keeps a record of temporary installation path
    * DONE (gglayer)
    

    wow!gglayer终于安装成功!!

    于是动手再重新安装yyplot

    > devtools::install_github("GuangchuangYu/yyplot")
    Downloading GitHub repo GuangchuangYu/yyplot@master
    ✓  checking for file ‘/private/var/folders/rr/3hs35sxn0lsfwvx91_w0vfhr0000gn/T/RtmpH6X08I/remotes1737726ddd400/GuangchuangYu-yyplot-91d2d33/DESCRIPTION’ ...
    ─  preparing ‘yyplot’:
    ✓  checking DESCRIPTION meta-information ...
    ─  checking for LF line-endings in source and make files and shell scripts
    ─  checking for empty or unneeded directories
    ─  building ‘yyplot_0.0.8.tar.gz’
       
    * installing *source* package ‘yyplot’ ...
    ** using staged installation
    ** R
    ** byte-compile and prepare package for lazy loading
    Error : .onLoad failed in loadNamespace() for 'sysfonts', details:
      call: dyn.load(file, DLLpath = DLLpath, ...)
      error: 无法载入共享目标对象‘/Library/Frameworks/R.framework/Versions/3.6/Resources/library/sysfonts/libs/sysfonts.so’::
      dlopen(/Library/Frameworks/R.framework/Versions/3.6/Resources/library/sysfonts/libs/sysfonts.so, 6): Library not loaded: /opt/X11/lib/libfreetype.6.dylib
      Referenced from: /Library/Frameworks/R.framework/Versions/3.6/Resources/library/sysfonts/libs/sysfonts.so
      Reason: image not found
    错误: unable to load R code in package ‘yyplot’
    停止执行
    ERROR: lazy loading failed for package ‘yyplot’
    * removing ‘/Library/Frameworks/R.framework/Versions/3.6/Resources/library/yyplot’
    错误: Failed to install 'yyplot' from GitHub:
      (由警告转换成)installation of package ‘/var/folders/rr/3hs35sxn0lsfwvx91_w0vfhr0000gn/T//RtmpH6X08I/file173772d895fef/yyplot_0.0.8.tar.gz’ had non-zero exit status
    

    仔细看报错的信息:

    Error : .onLoad failed in loadNamespace() for 'sysfonts', details:
      call: dyn.load(file, DLLpath = DLLpath, ...)
      error: 无法载入共享目标对
    
    错误: unable to load R code in package ‘yyplot’
    停止执行
    ERROR: lazy loading failed for package ‘yyplot’
    * removing ‘/Library/Frameworks/R.framework/Versions/3.6/Resources/library/yyplot’
    错误: Failed to install 'yyplot' from GitHub:
    

    google了Y叔的github yyplot的issue,看有没有人遇到类似的问题,结果,确实mac上有安装错误的issue
    发现了类似的问题

    image.png
    有人提出解决方法,下载XQuartz,地址https://www.xquartz.org/
    image.png
    出现的问题叫:
    sysfonts not loading/Image not found
    解答参考https://github.com/yixuan/showtext/issues/13

    并重新配置了经测试能登github的proxy
    git config --global http.proxy http://10X.1X6.1X5.1X9:443

    再次重新安装yyplot,终于安装成功!!

    > devtools::install_github("GuangchuangYu/yyplot")
    Downloading GitHub repo GuangchuangYu/yyplot@master
    ✓  checking for file ‘/private/var/folders/rr/3hs35sxn0lsfwvx91_w0vfhr0000gn/T/RtmpH6X08I/remotes173776ebf2b1f/GuangchuangYu-yyplot-91d2d33/DESCRIPTION’ ...
    ─  preparing ‘yyplot’:
    ✓  checking DESCRIPTION meta-information ...
    ─  checking for LF line-endings in source and make files and shell scripts
    ─  checking for empty or unneeded directories
    ─  building ‘yyplot_0.0.8.tar.gz’
       
    * installing *source* package ‘yyplot’ ...
    ** using staged installation
    ** R
    ** byte-compile and prepare package for lazy loading
    ** help
    *** installing help indices
    ** building package indices
    ** 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 (yyplot)
    

    6.直接下载packages.tar.gz安装

    install.packages("/Users/quyue/Desktop/adipocyteData/Course/ifnb.SeuratData_3.0.0.tar.gz", repos = NULL, type = "source")
    library(ifnb.SeuratData)
    

    说明:原创声明,部分观点参考https://zhuanlan.zhihu.com/p/50345757

    相关文章

      网友评论

        本文标题:R devtools安装yyplot(解决了mac安装错误问题)

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