Syncing Rcpp with external headers and libraries to build a batch geocoding package

被刻印的时光 ゝ 提交于 2019-12-08 03:32:54

问题


Good evening.

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.

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

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.

Thank you!

Gretchen

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.


回答1:


No book? No problem!

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.

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"

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

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

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

#include <header.h> 

vs.

#include "header.h"

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/

The second line is the most important.

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

For a more intense and interesting version, see dplyr.

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




回答2:


I was able to access the functions within the C library MyLibrary.dll using Coatless' response.

Here is my directory structure:

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

Here is my Makevars/Makevars.win file:

PKG_LIBS = -L../bin -lMyLibrary
PKG_CPPFLAGS =  -I../inst/include/


来源:https://stackoverflow.com/questions/36927141/syncing-rcpp-with-external-headers-and-libraries-to-build-a-batch-geocoding-pack

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!