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