0
votes

Using RCPP and RStudio/RTools on a Windows machine, I have created a package that batch geocodes NYC addresses. The package uses DLL and C header files from the NYC DCP Geosupport geocoding software which is free. I would love to share my package but have run into a roadblock when it comes to the paths in the Makevars/Makevars.win files. Since I am running this on my own machine, I have the luxury of locating where the geocoding software is installed on my machine and using this information for my Makevars/Makevars.win files:

##path 1 = location of NYCgeo.dll file after GBAT install
PKG_LIBS = -L"C:/Program Files/Geosupport Desktop Edition/Bin" -lNYCgeo 
##path 1 = location of NYCgeo.h and pac.h files after GBAT install
PKG_CPPFLAGS =  -I"C:/Program Files/Geosupport Desktop Edition/Include"

If I share this package, I will need this process to be dynamic as the user may have the geocoding software installed in a different location than mine. There is a environmental variable that is set during the geocoding software installation called GEOFILES:

Sys.getenv("GEOFILES")
[1] "C:\\Program Files\\Geosupport Desktop Edition\\fls\\"

I was wondering if there is a way that I can use this variable to set PKG_LIBS and PKG_CPPFLAGS... perhaps something like this:

Sys.setenv("PKG_LIBS"=paste0("-L'",gsub("\\\\", "/", gsub("fls.*$","Bin",Sys.getenv("GEOFILES"))),"' -lNYCgeo"))

Sys.setenv("PKG_CPPFLAGS"=paste0("-I'",gsub("\\\\", "/", gsub("fls.*$","Include",Sys.getenv("GEOFILES"))),"'"))

If this is possible, where would I place the preceding lines of R code? Would they go in the Rcpp.Exports.R file? I assume by setting PKG_LIBS and PKG_CPPFLAGS dynamically, there would no longer be a need for the Makevars/Makevars.win files.

EDIT: Hi, Dirk. I have noticed several packages that use environment variables in the makevars/makevars.win files. My issue is that I my environment variable needs to be altered (substitute "fls\" with "Bin" for PKG_LIBS and "src" for PKG_CPPFLAGS). My shell scripting is weak so I thought I could get away with applying regex and setting environments in R. Although my machine is Windows, I would like my package to be available to uses with other operating systems.

Thank you. Gretchen

1
Among the 9000+ packages on CRAN are 770+ using Rcpp --- and many have the same problem. You could do much worse than looking at existing sources. In general on Windows there is a tacit understanding that CRAN (or a user) will have files in a location specified by an environment variable. The rest is in code you can look at. - Dirk Eddelbuettel
Hello, Dirk. I agree, it is very easy to use an environment variable in the makevars files. My issue is that the environment variable that is created when the geocoding software is installed needs to be cleaned up before it is useful. I have been manually creating a new environment variable using gsub in R, using that new environmental variable in my makevars files and compiling. I am sure there must be a more elegant way to do this and would appreciate any suggestions. Thanks. - gmculp

1 Answers

1
votes

Pages 166-167 in Dirk's book had the answer. I needed to create a configure.win file:

#check if Geosupport  software is installed
if test -z "${GEOFILES}"; then
  echo "Please install Geosupport Software"
  exit 1
fi

GC_ROOT="$(echo ${GEOFILES} | sed 's/\\/\//g')"
GBAT_PATH="$(echo ${GC_ROOT} | sed 's/\/fls\///g')"


#check if installation is valid (i.e., dll is where it is supposed to be)
if [ -e "${GBAT_PATH}/Bin/NYCgeo.dll" ]; then
  GBAT_DLL="NYCgeo"
else
  echo "Please reinstall Geosupport Software"
  exit 1
fi

# replace all in Makevars.win
sed -e "s#@GBAT_PATH@#${GBAT_PATH}#g" -e "s#@GBAT_DLL@#${GBAT_DLL}#g"  \
src/Makevars.win.in > src/Makevars.win

... and a Makevars.win.in file in the src directory:

GBAT_PATH = @GBAT_PATH@
GBAT_DLL = @GBAT_DLL@

##path 1 = location of NYCgeo.dll file after GBAT install
PKG_LIBS = -L"$(GBAT_PATH)/Bin" -l$(GBAT_DLL)

##path 1 = location of NYCgeo.h and pac.h files after GBAT install
PKG_CPPFLAGS =  -I"$(GBAT_PATH)/Include"

When the package is compiled, a Makevars.win file is created in the src directory.