2

尝试在我的 Mac OS XI 上安装 R 包ggiraph时遇到了依赖 xml2 的问题。

对于此软件包和其他软件包的用户来说,这似乎是一个相当普遍的问题,因此在阅读了此处和其他地方的线程后,我确认了以下内容:

  • RStudio、R 及其所有软件包都是最新的
  • libxml2 安装在开发者版本中,使用自制软件
  • 我已将 libxml-2.0.pc 从 homebrew 文件夹复制到 /usr/local/lib/pkgconfig/
  • 我已将 /usr/local/lib/pkgconfig/ 添加到 PATH 和 PKG_CONFIG_PATH

在安装过程中我仍然收到以下错误消息。感谢您的帮助!

> install.packages("ggiraph")
Installing package into ‘/usr/local/lib/R/3.5/site-library’
(as ‘lib’ is unspecified)
also installing the dependency ‘xml2’

trying URL 'https://cran.rstudio.com/src/contrib/xml2_1.2.0.tar.gz'
Content type 'application/x-gzip' length 251614 bytes (245 KB)
==================================================
downloaded 245 KB

trying URL 'https://cran.rstudio.com/src/contrib/ggiraph_0.6.0.tar.gz'
Content type 'application/x-gzip' length 208710 bytes (203 KB)
==================================================
downloaded 203 KB

* installing *source* package ‘xml2’ ...
** package ‘xml2’ successfully unpacked and MD5 sums checked
Found pkg-config cflags and libs!
Using PKG_CFLAGS=-I/usr/include/libxml2
Using PKG_LIBS=-L/usr/lib -lxml2 -lz -lpthread -licucore -lm
------------------------- ANTICONF ERROR ---------------------------
Configuration failed because libxml-2.0 was not found. Try installing:
 * deb: libxml2-dev (Debian, Ubuntu, etc)
 * rpm: libxml2-devel (Fedora, CentOS, RHEL)
 * csw: libxml2_dev (Solaris)
If libxml-2.0 is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a libxml-2.0.pc file. If pkg-config
is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
--------------------------------------------------------------------
ERROR: configuration failed for package ‘xml2’
* removing ‘/usr/local/lib/R/3.5/site-library/xml2’
Warning in install.packages :
  installation of package ‘xml2’ had non-zero exit status
ERROR: dependency ‘xml2’ is not available for package ‘ggiraph’
* removing ‘/usr/local/lib/R/3.5/site-library/ggiraph’
Warning in install.packages :
  installation of package ‘ggiraph’ had non-zero exit status
4

1 回答 1

0

这是我在 macOS 上使用 Homebrew 和 libxml2 时经常遇到的问题。includeslibxml2 位于/path/to/includes/libxml2/libxml/编译器找不到的子目录中。

我在 R 中成功安装xml2了两件事:

  1. [...]/include/libxml创建指向的符号链接[...]/include/libxml2/libxml
  2. 将包含文件夹路径添加到INCLUDE_DIR

在终端中执行第 1 点。尽管您的安装文件路径可能不同,但我的 mac 上的 shell 命令是:

Bash > ln -s /usr/local/Cellar/libxml2/2.9.9_2/include/libxml2/libxml /usr/local/Cellar/libxml2/2.9.9_2/include/libxml`

在 RStudio 的 R 终端中执行第 2 点。我的mac上的命令是:

R > Sys.setenv(INCLUDE_DIR = paste("/usr/local/Cellar/libxml2/2.9.9_2/include", Sys.getenv("INCLUDE_DIR"), sep = ":"))`

然后安装xml2并最终ggiraph

R > install.packages(c("xml2", "ggiraph"))
于 2019-05-31T10:45:44.643 回答