如何指定安装R包时使用哪个R lib?

时间:2017-03-02 03:53:06

标签: r xml libxml2

I was trying to use a R package called "XML", 但安装后无法使用它:

# in R environment
> library("XML")
> XML::parseURI("")
Error in XML::parseURI("") : cannot parse URI 

问题原因是R无法找到当前版本的" libxml2"安装在我的目录中:

 echo $LD_LIBRARY_PATH /somewhere/Jun/Programme/libxml2-devel-2.9.1-2.1/usr/lib/:

检索有关libxml2库的版本的信息" XML"链接到

> path = unclass(getLoadedDLLs()[["XML"]])$path
> path
[1] "/misc/home/Jun/Programme/R-3.3.1/lib64/R/library/XML/libs/XML.so"
> system2("ldd",args=path)
                linux-vdso.so.1 =>  (0x00007fff2a9e8000)
                libxml2.so.2 => /usr/lib64/libxml2.so.2 (0x00002aefc088a000)  # XML is using a common "libxml2.so.2" not the one I installed. 
                libz.so.1 => //home/Jun/Programme/zlib-1.2.11/lib/libz.so.1 (0x00002aefc0bc8000)
                libm.so.6 => /lib64/libm.so.6 (0x00002aefc0de5000)
                libdl.so.2 => /lib64/libdl.so.2 (0x00002aefc1068000)
                ...

有任何建议吗?

为了制作" XML"链接到我的目录中安装的libxml2, 我做了这样的努力:

  1. 为libxml2设置PATH:

    echo $ LD_LIBRARY_PATH

    /somewhere/Jun/Programme/pcre-8.40/lib /:/某处月/ 6 /计划/ XZ-5.2.3 / LIB /:/某处月/ 6 /计划/ zlib的-1.2.11 /包含/:/某处月/ 6 /计划/ zlib的-1.2.11 / lib中/:/某处月/ 6 /计划/ bzip2-1.0.6 / lib中/:/某处月/ 6 /计划/ bzip2-1.0.6 /有/:/地方/君/程序/ GCC-6.1.0 / lib中/:/某处月/ 6 /计划/ GCC-6.1.0 / lib64下/:/某处月/ 6 /计划/的libxml2-devel的-2.9.1-2.1 / usr / lib目录/ :/somewhere/Jun/Programme/curl-7.52.1/lib /:/某处月/ 6 /计划/ libtool_CentOS6_64在/ usr / lib64下/:/家庭/申请/的openmpi-1.3.1 / lib目录下:/opt22/lsf83_exp/8.3 /linux2.6-glibc2.3-x86_64/lib:/opt/ups/lib

  2. 使用" - enable"使用配置指定lib重新编译R参数

    ./ configure --prefix = $ HOME / Program / R-3.3.1 --enable-R-shlib LDFLAGS =" -L / $ HOME / Program / zlib-1.2.11 / lib -L /$HOME/Programme/bzip2-1.0.6/lib -L ​​/ $ HOME / Program / xz-5.2.3 / lib -L ​​/ $ HOME / Program / pcre-8.40 / lib -L ​​/ $ HOME / Program / curl -7.52.1 / lib" CPPFLAGS =" -I / $ HOME / Program / zlib-1.2.11 / include -I / $ HOME / Program / bzip2-1.0.6 / include -I / $ HOME / Program / xz-5.2.3 /包括-I / $ HOME / Program / pcre-8.40 / include -I / $ HOME / Program / curl-7.52.1 / include"

  3. 安装" XML"使用configure参数:

    biocLite(" XML",configure.args =' - with-xml-config =" /somewhere/Jun/Programme/libxml2-devel-2.9.1-2.1的/ usr /斌/ XML2-配置"') BioC_mirror:http://bioconductor.org 使用Bioconductor 3.4(BiocInstaller 1.24.0),R 3.3.1(2016-06-21)。 安装包'XML' 尝试访问网址' http://cran.rstudio.com/src/contrib/XML_3.98-1.5.tar.gz'

    内容类型' application / x-gzip'长度1599213字节(1.5 MB)

    下载了1.5 MB ...

  4. 但它们似乎都不起作用:

    * installing *source* package ‘XML’ ...
    ** package ‘XML’ successfully unpacked and MD5 sums checked
    checking for gcc... gcc
    checking for C compiler default output file name... a.out
    checking whether the C compiler works... yes
    checking whether we are cross compiling... no
    checking for suffix of executables... 
    checking for suffix of object files... o
    checking whether we are using the GNU C compiler... yes
    checking whether gcc accepts -g... yes
    checking for gcc option to accept ISO C89... none needed
    checking how to run the C preprocessor... gcc -E
    checking for sed... /bin/sed
    checking for pkg-config... /usr/bin/pkg-config
    User defined xml-config: /somewhere/Jun/Programme/libxml2-devel-2.9.1-2.1/usr/bin/xml2-config, XML Version: 2, XML2: yes
    USE_XML2 = yes
    SED_EXTENDED_ARG: -r
    Minor 9, Patch 1 for 2.9.1
    Located parser file -I/usr/include/libxml2/parser.h
    checking for gzopen in -lz... yes
    checking for xmlParseFile in -lxml2... yes
    checking for xmlHashSize in -lxml2... yes
    Using built-in xmlHashSize
    Checking DTD parsing (presence of externalSubset)...
    checking for xmlHashSize in -lxml2... yes
    Found xmlHashSize
    checking for xmlOutputBufferCreateBuffer in -lxml2... yes
    have xmlOutputBufferCreateBuffer()
    checking for xmlDocDumpFormatMemoryEnc in -lxml2... yes
    checking libxml/xmlversion.h usability... yes
    checking libxml/xmlversion.h presence... yes
    checking for libxml/xmlversion.h... yes
    Expat:  FALSE
    Checking for return type of xmlHashScan element routine.
    No return value for xmlHashScan
    xmlNs has a context field
    Checking for cetype_t enumeration
    Using recent version of R with cetype_t enumeration type for encoding
    checking for xmlsec1-config... /usr/bin/xmlsec1-config
    nodegc default 
    xml-debug default 
    No XML_WITH_ZLIB enumeration value.
    Version has xmlHasFeature()
    
    ****************************************
    Configuration information:
    
    Libxml settings
    
    libxml include directory: -I/usr/include/libxml2
    libxml library directory: -lxml2 -lz -lm -ldl -lz  -lxml2
    libxml 2:                 -DLIBXML2=1
    

1 个答案:

答案 0 :(得分:0)

我想我找到了解决方案。而不是使用rpm来安装" libxml2" (我很抱歉我没有在我的帖子中提到它;我没有意识到这可能是我麻烦的原因),我应该编译" libxml2"来源。

对于有类似问题的人:

下载当前版本的libxml2 http://www.linuxfromscratch.org/blfs/view/svn/general/libxml2.html

按照上述链接的说明操作。

安装两点:

1

./configure --prefix=$HOME/Programme --disable-static --with-history --with-zlib=/somewhere/Jun/Programme/zlib-1.2.11 && make

你必须指定zlib(--with);这也意味着您必须安装zlib。我不得不添加" - 用"使configure工作。

  1. 说明中说明您必须致电" make install"作为root用户,但不是,你不必这样做。

  2. 为已安装的" libxml2"设置PATH

  3. 重新安装R包" XML"。