zoukankan      html  css  js  c++  java
  • Error in .External2(C_X11, paste0("png::", filename), g$width, g$height, : 解决linux R绘图问题

    1、R-4.0.3安装过程中隐患

    2、查看当前系统

    [root@centos8 test]# cat /etc/redhat-release
    CentOS Linux release 8.3.2011
    [root@centos8 test]# hostnamectl
       Static hostname: centos8
             Icon name: computer-vm
               Chassis: vm
            Machine ID: d5fd22581df140c192815b766d6ec0d7
               Boot ID: c7ff573d91e34d83a0c2b0caec78aafc
        Virtualization: vmware
      Operating System: CentOS Linux 8
           CPE OS Name: cpe:/o:centos:centos:8
                Kernel: Linux 4.18.0-240.el8.x86_64
          Architecture: x86-64

    3、查看R版本

    [root@centos8 test]# R --version
    R version 4.0.3 (2020-10-10) -- "Bunny-Wunnies Freak Out"
    Copyright (C) 2020 The R Foundation for Statistical Computing
    Platform: x86_64-pc-linux-gnu (64-bit)
    
    R is free software and comes with ABSOLUTELY NO WARRANTY.
    You are welcome to redistribute it under the terms of the
    GNU General Public License versions 2 or 3.
    For more information about these matters see
    https://www.gnu.org/licenses/.

    4、启动R,检查绘图功能

    [root@centos8 test]# R
    
    R version 4.0.3 (2020-10-10) -- "Bunny-Wunnies Freak Out"
    Copyright (C) 2020 The R Foundation for Statistical Computing
    Platform: x86_64-pc-linux-gnu (64-bit)
    
    R is free software and comes with ABSOLUTELY NO WARRANTY.
    You are welcome to redistribute it under certain conditions.
    Type 'license()' or 'licence()' for distribution details.
    
      Natural language support but running in an English locale
    
    R is a collaborative project with many contributors.
    Type 'contributors()' for more information and
    'citation()' on how to cite R or R packages in publications.
    
    Type 'demo()' for some demos, 'help()' for on-line help, or
    'help.start()' for an HTML browser interface to help.
    Type 'q()' to quit R.
    
    > capabilities()
           jpeg         png        tiff       tcltk         X11        aqua
          FALSE       FALSE       FALSE       FALSE       FALSE       FALSE
       http/ftp     sockets      libxml        fifo      cledit       iconv
           TRUE        TRUE        TRUE        TRUE        TRUE        TRUE
            NLS     profmem       cairo         ICU long.double     libcurl
           TRUE       FALSE       FALSE       FALSE        TRUE        TRUE

    5、测试

    > getwd()
    [1] "/home/test"
    > dir()
    character(0)
    > png("test.png")
    Error in .External2(C_X11, paste0("png::", filename), g$width, g$height,  :
      unable to start device PNG
    In addition: Warning message:
    In png("test.png") : no png support in this version of R
    >  jpeg("test.jpg")
    Error in .External2(C_X11, paste0("jpeg::", quality, ":", filename), g$width,  :
      unable to start device JPEG
    In addition: Warning message:
    In jpeg("test.jpg") : no jpeg support in this version of R
    > bmp("test.bmp")
    Error in .External2(C_X11, paste0("bmp::", filename), g$width, g$height,  :
      unable to start device BMP
    In addition: Warning message:
    In bmp("test.bmp") : unable to open connection to X11 display ''

      > quit()
      Save workspace image? [y/n/c]: n

     

    6、

    [root@centos8 test]# yum install libpng-devel libtiff-devel libjpeg-turbo-devel pango-devel libpng-devel -y
    …………
    …………
      Verifying        : freetype-2.9.1-4.el8_3.1.x86_64                                                                           23/24
      Verifying        : freetype-2.9.1-4.el8.x86_64                                                                               24/24
    Installed products updated.
    
    Upgraded:
      freetype-2.9.1-4.el8_3.1.x86_64
    
    Installed:
      cairo-devel-1.15.12-3.el8.x86_64              expat-devel-2.2.5-4.el8.x86_64             fontconfig-devel-2.13.1-3.el8.x86_64
      freetype-devel-2.9.1-4.el8_3.1.x86_64         fribidi-devel-1.0.4-8.el8.x86_64           glib2-devel-2.56.4-8.el8.x86_64
      graphite2-devel-1.3.10-10.el8.x86_64          harfbuzz-devel-1.7.5-3.el8.x86_64          libXext-devel-1.3.4-1.el8.x86_64
      libXft-devel-2.3.3-1.el8.x86_64               libXrender-devel-0.9.10-7.el8.x86_64       libicu-devel-60.3-2.el8_1.x86_64
      libjpeg-turbo-devel-1.5.3-10.el8.x86_64       libpng-devel-2:1.6.34-5.el8.x86_64         libtiff-devel-4.0.9-18.el8.x86_64
      libuuid-devel-2.32.1-24.el8.x86_64            pango-devel-1.42.4-6.el8.x86_64            pcre-cpp-8.42-4.el8.x86_64
      pcre-devel-8.42-4.el8.x86_64                  pcre-utf16-8.42-4.el8.x86_64               pcre-utf32-8.42-4.el8.x86_64
      pixman-devel-0.38.4-1.el8.x86_64
    
    Complete!

    7、

    [root@centos8 R-4.0.3]# cd /home/R-4.0.3/   ## R安装包所在目录
    [root@centos8 R-4.0.3]# make uninstall
    …………
    …………
    make[1]: Leaving directory '/home/R-4.0.3/doc'
    make[1]: Entering directory '/home/R-4.0.3/tools'
    make[1]: Nothing to be done for 'uninstall'.
    make[1]: Leaving directory '/home/R-4.0.3/tools'
    make[1]: Entering directory '/home/R-4.0.3/m4'
    make[1]: Nothing to be done for 'uninstall'.
    make[1]: Leaving directory '/home/R-4.0.3/m4'

    8、

    [root@centos8 R-4.0.3]# ./configure --prefix=/home/software/R/ --enable-R-shlib
    …………
    …………
      Interfaces supported:        X11
      External libraries:          pcre2, readline, curl
      Additional capabilities:     PNG, JPEG, TIFF, NLS, cairo, ICU
      Options enabled:             shared R library, shared BLAS, R profiling
    
      Capabilities skipped:
      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

    9、

    [root@centos8 R-4.0.3]# make
    …………
    …………
    make[2]: Leaving directory '/tmp/Rjavareconf.OW1bvr'
    
    
    JAVA_HOME        : /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.275.b01-1.el8_3.x86_64/jre
    Java library path: $(JAVA_HOME)/lib/amd64/server
    JNI cpp flags    : -I$(JAVA_HOME)/../include -I$(JAVA_HOME)/../include/linux
    JNI linker flags : -L$(JAVA_HOME)/lib/amd64/server -ljvm
    Updating Java configuration in /home/R-4.0.3
    Done.
    
    make[1]: Leaving directory '/home/R-4.0.3'

    10、

    [root@centos8 R-4.0.3]# make install
    …………
    …………
    mkdir -p -- /home/software/R/lib64/R/library
    installing packages ...
      building HTML index ...
    make[2]: Leaving directory '/home/R-4.0.3/src/library'
    make[1]: Leaving directory '/home/R-4.0.3/src'
    make[1]: Entering directory '/home/R-4.0.3/tests'
    make[1]: Nothing to be done for 'install'.
    make[1]: Leaving directory '/home/R-4.0.3/tests'

    11、测试R

    [root@centos8 R-4.0.3]# cd /home/test/
    [root@centos8 test]# R
    
    R version 4.0.3 (2020-10-10) -- "Bunny-Wunnies Freak Out"
    Copyright (C) 2020 The R Foundation for Statistical Computing
    Platform: x86_64-pc-linux-gnu (64-bit)
    
    R is free software and comes with ABSOLUTELY NO WARRANTY.
    You are welcome to redistribute it under certain conditions.
    Type 'license()' or 'licence()' for distribution details.
    
      Natural language support but running in an English locale
    
    R is a collaborative project with many contributors.
    Type 'contributors()' for more information and
    'citation()' on how to cite R or R packages in publications.
    
    Type 'demo()' for some demos, 'help()' for on-line help, or
    'help.start()' for an HTML browser interface to help.
    Type 'q()' to quit R.
    
    > capabilities()
           jpeg         png        tiff       tcltk         X11        aqua
           TRUE        TRUE        TRUE       FALSE       FALSE       FALSE
       http/ftp     sockets      libxml        fifo      cledit       iconv
           TRUE        TRUE        TRUE        TRUE        TRUE        TRUE
            NLS     profmem       cairo         ICU long.double     libcurl
           TRUE       FALSE        TRUE        TRUE        TRUE        TRUE
    > dir()
    character(0)
    > png("test.png")
    > plot(1:10,col="red",pch=15,cex=2)
    > dev.off()
    null device
              1
    > dir()
    [1] "test.png"
    > jpeg("test.jpg")
    > plot(1:10,col="blue",pch=17,cex=2)
    > dev.off()
    null device
              1
    > dir()
    [1] "test.jpg" "test.png"
    > bmp("test.bmp")
    > plot(1:10,col="purple",pch=18,cex=2)
    > dev.off()
    null device
              1
    > dir()
    [1] "test.bmp" "test.jpg" "test.png"

     

     

     问题解决。

    参考:

    http://blog.sina.com.cn/s/blog_db13b2400102v5p2.html

    https://www.cnblogs.com/liujiaxin2018/p/14357922.html

    https://blog.csdn.net/wa2003/article/details/46310811/

    https://stackoverflow.com/questions/17243648/cant-display-png

     

  • 相关阅读:
    python第九十天----jquery
    收藏所用C#技术类面试、笔试题汇总
    线程内打开窗体
    有关正则表达式的一些总结
    XML与Object的范型转换
    开始工作了
    Oracle查询数据表结构(字段,类型,大小,备注)
    MyEclipse安装jbpm插件
    MyEclipse启动tomcat增加内存配置
    extJs常用的四种Ajax异步提交
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14363308.html
Copyright © 2011-2022 走看看