如何在R中为H3地理空间索引系统安装“ h3”库

问题描述

我的理解是,“ H3地理空间索引系统”是Uber开发的一种“坐标系统”,其主要特征是它基于分层六边形的系统。 “他”是R语言中的一个库,可以帮助人们使用此“ H3空间参考系统”中的数据,但不存储在CRAN中,而是存储在GitHub(https://github.com/crazycapivara/h3-r)中。

但是,我无法在R中安装该库。我已经将其安装了托盘(如GitHub中的说明所示):

install.packages("devtools")
devtools::install_github("crazycapivara/h3-r")

但是它不起作用,并且正在返回此消息:

devtools::install_github("crazycapivara/h3-r")
Error in loadNamespace(j <- i[[1L]],c(lib.loc,.libPaths()),versionCheck = vI[[j]]) : 
 there is no package called ‘digest’

然后,我在“ R-cloud”中执行相同的步骤,但得到另一个错误

h3_hex-ring.cpp:2:22: Fatal error: h3/h3api.h: No such file or directory
compilation terminated.
/opt/R/4.0.3/lib/R/etc/Makeconf:181: recipe for target 'h3_hex-ring.o' Failed
make: *** [h3_hex-ring.o] Error 1
ERROR: compilation Failed for package ‘h3’
* removing ‘/home/rstudio-user/R/x86_64-pc-linux-gnu-library/4.0/h3’
Error: Failed to install 'h3' from GitHub:
  (converted from warning) installation of package ‘/tmp/RtmpzwLngc/file1698ded56/h3_3.3.2.tar.gz’ had non-zero exit status

我查看了该GitHub,但无法找出问题所在。有没有人成功地在R上安装了该库,或者知道使用这种空间参考系统的其他库?

解决方法

您的直接问题是您似乎需要在安装 h3-r 之前安装依赖包“digest”(可能还有其他包)。首先尝试这样做(我假设您也能够构建底层 C 包)。

我不确定 h3-r 的维护情况如何,因此它可能不适用于 R 的最新版本。如果您想尝试通过 js 转译在 R 中使用 H3,请尝试 https://github.com/obrl-soil/h3jsr (免责声明:我是作者)。它可能会处理非常大的数据集,但对于大多数较小的应用程序应该没问题。