A usethis-style helper that configures a downstream R package to link against VTK via rvtk. It performs the following steps:
Adds
rvtkto theImportsfield ofDESCRIPTION.Writes
src/Makevarsthat queries compiler and linker flags at install time by callingtools/configure.R.Writes
src/Makevars.winwith the Windows-specific$(shell ...)syntax that does the same.Writes
tools/configure.Rthat callsCppFlags()andLdFlagsFile()with the requested VTK modules.Adds
src/vtk_libs.rspto.gitignore(it is generated at install time and must not be committed).Creates
R/rvtk_imports.Rwith a minimal@importFrom rvtkroxygen tag so thatR CMD checkdoes not complain about rvtk being listed inImportswithout any function import in the R code.
After running use_rvtk() the downstream package is fully configured: VTK
compiler and linker flags are resolved automatically at R CMD INSTALL time
on all platforms without any shell configure / configure.win scripts.
Arguments
- modules
A character vector of VTK module names to link against, or
NULL(the default) to link the full set of VTK modules bundled with rvtk. These are passed toLdFlagsFile()in the generatedtools/configure.R. The pre-built archives are static libraries, so the linker extracts only the object files actually referenced by your code: linking everything by default cannot fail with "missing module" symbols (e.g. thevtkParallelDIY/vtkIOCellGridfailures seen with older curated defaults), and passing a subset such asc("vtkIOLegacy", "vtkCommonCore")is an optimisation that reduces link time and keeps the resulting binary smaller for packages that use only part of VTK.- path
Path to the root of the downstream package. Defaults to the current working directory.
Examples
# Configure a minimal package in a temporary directory
pkg <- file.path(tempdir(), "mypkg")
dir.create(pkg, recursive = TRUE)
writeLines(c(
"Package: mypkg",
"Title: My Package",
"Description: A package that links against VTK.",
"Version: 0.0.1"
), file.path(pkg, "DESCRIPTION"))
use_rvtk(path = pkg)
#> ✔ Added rvtk to Imports in DESCRIPTION.
#> ✔ Writing src/Makevars.
#> ✔ Writing src/Makevars.win.
#> ✔ Writing tools/configure.R.
#> ✔ Adding "src/vtk_libs.rsp" to .gitignore.
#> ✔ Writing R/rvtk_imports.R.
#> ✔ Package mypkg is now configured to link against VTK via rvtk.
list.files(pkg, recursive = TRUE)
#> [1] "DESCRIPTION" "R/rvtk_imports.R" "src/Makevars"
#> [4] "src/Makevars.win" "tools/configure.R"
unlink(pkg, recursive = TRUE)
