简体   繁体   中英

how to specify which R lib to use when installing a R package?

I was trying to use a R package called "XML" , but had trouble to use it after installation:

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

the issue turned out to be that R could not find the current version of "libxml2" installed in my directory:

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

retrieve information about the version of the libxml2 library "XML" linking to

> 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)
                ...

Any suggestion to do that?

in order to make "XML" link to the libxml2 installed in my directory, I made such efforts:

  1. setting PATH for libxml2:

    echo $LD_LIBRARY_PATH

    /somewhere/Jun/Programme/pcre-8.40/lib/:/somewhere/Jun/Programme/xz-5.2.3/lib/:/somewhere/Jun/Programme/zlib-1.2.11/include/:/somewhere/Jun/Programme/zlib-1.2.11/lib/:/somewhere/Jun/Programme/bzip2-1.0.6/lib/:/somewhere/Jun/Programme/bzip2-1.0.6/include/:/somewhere/Jun/Programme/gcc-6.1.0/lib/:/somewhere/Jun/Programme/gcc-6.1.0/lib64/:/somewhere/Jun/Programme/libxml2-devel-2.9.1-2.1/usr/lib/:/somewhere/Jun/Programme/curl-7.52.1/lib/:/somewhere/Jun/Programme/libtool_CentOS6_64/usr/lib64/:/home/appl/openmpi-1.3.1/lib:/opt22/lsf83_exp/8.3/linux2.6-glibc2.3-x86_64/lib:/opt/ups/lib

  2. recompile R with configuration specifying lib using "--enable" argument

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

  3. install "XML" with configure arguments:

    biocLite("XML",configure.args='--with-xml- config="/somewhere/Jun/Programme/libxml2-devel-2.9.1-2.1/usr/bin/xml2-config"') BioC_mirror: http://bioconductor.org Using Bioconductor 3.4 (BiocInstaller 1.24.0), R 3.3.1 (2016-06-21). Installing package(s) 'XML' trying URL ' http://cran.rstudio.com/src/contrib/XML_3.98-1.5.tar.gz '

    Content type 'application/x-gzip' length 1599213 bytes (1.5 MB)

    downloaded 1.5 MB ...

but none of them seemed to work:

* 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

I think I have found the solution. Instead of using rpm to install "libxml2" (I apologize that I did not mention it in my post; I didn't realize that it could be the cause of my trouble), I ought to have compiled "libxml2" from source.

For people that have a similar issue:

Download the current version of libxml2 http://www.linuxfromscratch.org/blfs/view/svn/general/libxml2.html ,

following the instructions of the link above.

Two points for installation:

1.

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

you have to specify zlib (--with); this also means that you have to have zlib installed. I had to add "--with" to make configure work.

  1. The instructions state that you have to call "make install" as root user, but no, you don't have to do this.

  2. Set the PATH for your installed "libxml2".

  3. Reinstall your R package "XML".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM