Dynamically setting PKG_LIBS and PKG_CPPFLAGS
<p>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 <a href="https://www1.nyc.gov/site/planning/data-maps/open-data/dwn-gde-home.page" rel="nofollow">NYC DCP Geosupport</a> 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:</p>

<pre><code>##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"
</code></pre>

<p>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:</p>

<pre><code>Sys.getenv("GEOFILES")
[1] "C:\\Program Files\\Geosupport Desktop Edition\\fls\\"
</code></pre>

<p>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:</p>

<pre><code>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"))),"'"))
</code></pre>

<p>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.  </p>

<p>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.  </p>

<p>Thank you.
Gretchen     </p>