[英]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: 我试图使用一个名为“ XML”的R包 ,但是在安装后无法使用它:
# 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: 问题原来是R无法在我的目录中找到安装的“ libxml2”的当前版本:
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 检索有关链接到的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)
...
Any suggestion to do that? 有什么建议吗?
in order to make "XML" link to the libxml2 installed in my directory, I made such efforts: 为了使“ XML”链接到安装在我的目录中的libxml2,我做了以下努力:
setting PATH for libxml2: 为libxml2设置PATH:
echo $LD_LIBRARY_PATH 回声$ 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 /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目录
recompile R with configuration specifying lib using "--enable" argument 使用“ --enable”参数用指定lib的配置重新编译R
./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" ./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“
install "XML" with configure arguments: 使用配置参数安装“ XML”:
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). 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使用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 ' 安装包“ XML”并尝试使用网址“ http://cran.rstudio.com/src/contrib/XML_3.98-1.5.tar.gz ”
downloaded 1.5 MB ... 下载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. 与其使用rpm安装“ libxml2”,(我很抱歉在我的帖子中没有提到它;我没有意识到这可能是造成麻烦的原因),我应该从源代码编译“ libxml2”。
For people that have a similar issue: 对于有类似问题的人:
Download the current version of libxml2 http://www.linuxfromscratch.org/blfs/view/svn/general/libxml2.html , 从http://www.linuxfromscratch.org/blfs/view/svn/general/libxml2.html下载libxml2的当前版本,
following the instructions of the link above. 请按照上面链接的说明进行操作。
Two points for installation: 安装两点:
1. 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); 您必须指定zlib(--with); this also means that you have to have zlib installed. 这也意味着您必须安装zlib。 I had to add "--with" to make configure
work. 我必须添加“ --with”以使configure
工作。
The instructions state that you have to call "make install" as root user, but no, you don't have to do this. 说明说明您必须以root用户身份调用“ make install”,但没有,您不必这样做。
Set the PATH
for your installed "libxml2". 为您安装的“ libxml2”设置PATH
。
Reinstall your R package "XML". 重新安装您的R包“ XML”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.