-
Hi developers of sf and terra, For R package vol2birdR I'm trying to replicate the copying of the proj library data as implemented in sf and terra. My package needs access to the I was reading through the discussions between @jeroen @rsbivand and @edzer in issues #1605 and #1933 where copying of the proj data is discussed. As I understand the copy occurs in this line: Line 233 in 3aee3e4 However for this to work both the Lines 209 to 240 in 3aee3e4 I can find no instance in the sf and terra code base where these environment variables are set. It's also clear that the package source for sf/terra do not contain the proj library data: If I want to mirror the solution in sf/terra, how do I make sure that the |
Beta Was this translation helpful? Give feedback.
Replies: 11 comments 13 replies
-
|
Beta Was this translation helpful? Give feedback.
-
You should not set these variables yourself; the owner of the build server sets For the r-universe builds that you can find on https://cran.dev/vol2birdR these variables were set by the macos-prep action. But it doesn't matter how they get set, all your package needs to do is respect the values from the environment variables on the current server. It is correct that no data files are included in the source package, as the version of the data needs to match the version of libproj that your package was linked to. Again, all these things are provided by the build server. |
Beta Was this translation helpful? Give feedback.
-
Hi @jeroen, I hope I can pick your brain for one more follow up question (let me know if I better ask this to CRAN maintainers or elsewhere instead): I implemented sf's copy mechanism for the proj library data but am noticing the latest CRAN builds do not include a |
Beta Was this translation helpful? Give feedback.
-
Note r-universe and CRAN are different build servers. I can only speak for the binaries you can download on https://adokter.r-universe.dev/vol2birdR and I think those packages include those For the CRAN binaries, you can find the build log here, perhaps these can tell you what is happening: |
Beta Was this translation helpful? Give feedback.
-
@adokter I had to dig in a little, but you may need to add flags needed for your package to the CRAN macosx build system to override the default flags, see this comment: #1703 (comment) where you see how this is done for a set of other CRAN packages using one or more of GEOS/GDAL/PROJ. |
Beta Was this translation helpful? Give feedback.
-
Using --configure-args='--with-data-copy=yes --with-proj-data=' |
Beta Was this translation helpful? Give feedback.
-
I can confirm the configure arguments mentioned above do the trick, and I've reached out to CRAN and @s-u for vol2birdR to be added to |
Beta Was this translation helpful? Give feedback.
-
@adokter please note that this is really a bug in the package. The package should not rely on files outside of its installation, so it should copy the data at build time - it should not require additional arguments to do so. The additional arguments were a hack for one package way back, but instead of fixing the problem it seems others have copied the same hack. It was never intended to be used by more packages. This is a good opportunity to finally fix that problem. Any packages that uses |
Beta Was this translation helpful? Give feedback.
-
I did not design this, but IIUC the reasoning is that the default behavior assumes the package is built for local use and dynamically linked against a local gdal/proj which can automatically find these data files locally on the system, so we don't need to copy them. Only in the case where you want to create a binary package which can be redistributed by itself, and you are on a platform that can do this (i.e macos) we need to copy all these extra data files into the package directory. But this is a choice of the builder, not the package author, so that is why it is opt-in using Always copying all data files by default on all platforms (especially on Linux), seems like a bad idea because they can be huge, and even on MacOS it is really only needed if you are trying to build something redistributable, which is only the case for CRAN. |
Beta Was this translation helpful? Give feedback.
-
@s-u I don't think that relying on a single package to provide |
Beta Was this translation helpful? Give feedback.
-
The copying of share/proj and share/gdal into packages at installation is and has always been applicable only to installable binaries where we know with some certainty that those resources cannot be located by R contributed packages at install time. This applies to Windows and macOS CRAN binaries, and probably to off-CRAN binaries. @edzer has explained about the run-time version check applied to When the mechanism was introduced, there were only text files, needed for PROJ (and GDAL) to work. From GDAL 3 and PROJ 6, From PROJ 7, https://cdn.proj.org/ was launched to provide content download on demand for high-precision grids used for specified parts of thw world, or even of countries or parts of countries, to be cached locally. Typically a local appdata directory (for me Consequently, bundlers adding all the grids to PROJ package dependencies (OSGeo4W is one such) only makes sense if you know that all users are often offline when transforming data, and that they certainly need grids covering the whole world. The old proj-datumgrid bundle that used to be all there was, and was OK to copy before PROJ 7, has a zipped size of 6MB. The new proj-datum bundle is 745MB compressed, uncompressed 790MB. Bundlers have typically mistaken the old setup for the new, and ignored the CDN, which is efficient and parsimonious. Both It might even make sense to hotpatch
to turn the CDN on by default in the first variable - the first 5 variables apply to the CDN. For all other than CRAN static binary package builds (possibly PROJ_GDAL_DATA_COPY and PROJ_LIB set in r-universe builds hopefully only for Windows/macOS), we should rely on the dependences having been set correctly by the bundler/packager, so that the PROJ/GDAL binary libraries know where to find installed files such as For those who relish complications, running R with spatial packages with |
Beta Was this translation helpful? Give feedback.
You should not set these variables yourself; the owner of the build server sets
PROJ_GDAL_DATA_COPY
andPROJ_LIB
for you to let your package know where it can find those files.For the r-universe builds that you can find on https://cran.dev/vol2birdR these variables were set by the macos-prep action. But it doesn't matter how they get set, all your package needs to do is respect the values from the environment variables on the current server.
It is correct that no data files are included in the source package, as the version of the data needs to match the version of libproj that your package was linked to. Again, all these things are provided by the build server.