将Rcpp与外部标头和库同步以构建批处理地理编码包 [英] Syncing Rcpp with external headers and libraries to build a batch geocoding package

查看:53
本文介绍了将Rcpp与外部标头和库同步以构建批处理地理编码包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

晚上好.

目标:我正在尝试在运行Windows的计算机上使用RPP在RCPP的基础上,基于纽约市城市规划局的Geosupport软件构建批处理地理编码程序包.除了座标外,Geosupport还返回了许多有用的信息,包括建筑物识别号和人口普查地理位置.我认为这样的软件包对于研究NYC数据的研究人员和社区倡导者可能很有用.

GOAL: I am attempting to build a batch geocoding package based on the New York City Department of City Planning's Geosupport software using RCPP from within RStudio on a machine running Windows. Geosupport returns a lot of useful information besides coordinates including building identification number and census geographies. I think such a package has the potential to be very useful to researchers and community advocates working with NYC data.

背景:可在纽约市DCP网站.该下载带有用于批处理地理编码的界面(称为GBAT).此外,还提供了头文件,数据文件和库文件,以便用户可以对使用C,C ++或VB构建的应用程序进行地理编码.库文件具有DLL扩展名,并且是用C编译的(不是C ++,我与一位开发人员联系过).

BACKGROUND: Geosupport is available as a free download on the NYC DCP website. The download comes with a interface for batch geocoding (known as GBAT). In addition, header, data and library files are provided so users can geocode from an application built using C, C++, or VB. The library files have a DLL extension and were compiled in C (not C++, I checked with one of the developers).

状态:到目前为止,我已经能够包含头文件并设置工作区.尝试使用C库中的函数时遇到问题.我一直在阅读编写R扩展-使用Makevars",但仍不确定如何进行.我使用RStudio的Rtools和RCPP构建了程序包,但未生成makevars文件.我购买了Dirk的书(类似于我的帖子中提到了这本书),但尚未到货.

STATUS: Thus far, I have been able to include the header files and set up work areas. I run into problems when I attempt to use the functions from the C libraries. I have been reading Writing R Extensions - Using Makevars but I am still uncertain about how to proceed. I built my package using RStudio's Rtools with RCPP and a makevars file was not generated. I purchased Dirk's book (which is referenced in postings similar to mine) but it has not arrived, yet.

谢谢!

Gretchen

更新的代码... 2016年5月3日美国东部标准时间19:45: 根据Coatless的建议,我创建了一个 GitHub存储库.我还创建了一个Makevars.win和Makevars文件,并将头文件重定位到inst/include.标头工作正常,但我仍然不知道如何处理这些库.此外,驱动地理编码器的基础数据文件对于GitHub太大(1.85 GB).我将尝试从家用计算机使用Git LFS添加它们.

UPDATED CODE... 05.03.2016 at 19:45 EST: Per Coatless's suggestion, I created a GitHub repository. I also created a Makevars.win and Makevars files and relocated my header files to inst/include. The headers work OK but I still do not know what to do with the libraries. Also, the underlying data files that drive the geocoder are too large for GitHub (1.85 GB). I will try to add them using Git LFS from my home computer.

推荐答案

没有书吗?没问题!

首先,尝试通过Rcpp.package.skeleton()创建程序包框架来了解程序包的结构,或使用RStudio的

First, try to understand the package structure by creating a package skeleton via Rcpp.package.skeleton() or use RStudio's Create an Rcpp Package bit.

对于其他所有内容,小插曲并在 Rcpp的画廊中在线.

For everything else, there are lots of examples in the vignettes and online in Rcpp's gallery.

先行尝试,造成困难的主要原因是使用:

First off the bat, the main reason for the difficult is the use of:

#include "../Include/NYCgeo.h"

这不是一个好的样式,因为它与R软件包的典型文件结构背道而驰.

This is not a good style as it goes against the file structure typical of R packages.

当尝试使用库头文件时,应选择以下任一种包结构:

When trying to use library headers, one should opt for a package structure of either:

R/
src/
 |- Makevars
 |- Makevars.win
 |- header.h
 |- action.cpp
man/
DESCRIPTION
NAMESPACE

在这种方法下,您的头文件仅限于软件包.为了在DESCRIPTION文件中启用LinkingTo:方法并实现更好的包含,您应该针对的结构是:

Under this approach, your header files are restricted solely to the package. To enable a LinkingTo: approach within the DESCRIPTION file and generally better inclusions, the structure you should aim for is:

R/
inst/
 |- include/
    |- header.h
src/
 |- Makevars
 |- Makevars.win
 |- action.cpp
man/
DESCRIPTION
NAMESPACE

因此,您可以在action.cpp文件中使用:

Thus, in the action.cpp file you can just use:

#include <header.h> 

vs.

#include "header.h"

现在,这样说,/src中的MakevarsMakevars.win文件的内容在/inst/include中包含标头时应为:

Now, with that being said, contents for the Makevars and Makevars.win files in /src when including headers in the /inst/include should be:

PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
PKG_CPPFLAGS =  -I../inst/include/

第二行是最重要的.

有关文件包含的非常简单的示例,请参见 sitmo {免责声明:我写了R包}

For a very simplistic example of file inclusions, see sitmo {disclaimer: I wrote the R package}.

有关更激烈和有趣的版本,请参见 dplyr .

For a more intense and interesting version, see dplyr.

如果您将完整的代码扔到GitHub上,则可以提供更多帮助.

If you code toss the complete code onto GitHub, more help could be provided.

这篇关于将Rcpp与外部标头和库同步以构建批处理地理编码包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆