Package 'rvtk'

Title: Bindings for the Visualization Toolkit ('VTK')
Description: Makes the Visualization Toolkit ('VTK') available to R packages so their C++ code can link against it without requiring users to install 'VTK' manually. When no suitable system installation is found, pre-built static libraries are downloaded automatically. Downstream packages declare 'Imports: rvtk' and obtain the correct compiler and linker flags at install time from CppFlags(), LdFlags(), and LdFlagsFile(); the use_rvtk() helper writes all required build-time files in one step. Pre-built libraries cover all VTK modules that can be built without external dependencies, and downstream packages can opt in to linking only the modules they need.
Authors: Aymeric Stamm [aut, cre, cph] (ORCID: <https://orcid.org/0000-0002-8725-3654>)
Maintainer: Aymeric Stamm <[email protected]>
License: MIT + file LICENSE
Version: 0.3.0
Built: 2026-11-25 18:23:09 UTC
Source: https://github.com/astamm/rvtk

Help Index


VTK modules available in this installation

Description

Returns the VTK modules that the installation detected at configure time can link against. With the pre-built archives this is the full module list shipped (recorded in inst/vtk_modules.txt); with a system VTK it is derived from the static libraries and linker flags recorded in vtk.conf.

Usage

available_modules()

Details

This lets downstream packages fail fast at install time when a module they require is missing from a system VTK installation, with a hint to compile VTK with that module or fall back to the pre-built archives (which ship all modules).

Value

A character vector of available VTK module names, e.g. c("vtkCommonCore", "vtkIOLegacy", ...), sorted.

See Also

LdFlagsFile()

Examples

mods <- available_modules()

Compiler flags for packages linking against VTK

Description

Returns the C pre-processor flags (-I paths) required to compile C++ code that includes VTK headers. Intended to be called from a downstream package's configure or configure.win script:

Usage

CppFlags()

Details

VTK_CPPFLAGS="$("${R_HOME}/bin/Rscript" --vanilla -e "rvtk::CppFlags()")"

For the recommended one-call setup of a downstream package, see use_rvtk(); it wires this function (and LdFlagsFile()) into the package's build files automatically.

Value

A single character string of compiler flags, written to stdout (so that it can be captured by shell command substitution in configure) and returned invisibly.

See Also

use_rvtk()

Examples

flags <- CppFlags()

Linker flags for packages linking against VTK

Description

Returns the linker flags (-L paths and -l library names) required to link C++ code against VTK. Intended to be called from a downstream package's configure or configure.win script:

Usage

LdFlags(modules = NULL, check = TRUE)

Arguments

modules

A character vector of VTK module names to link against, e.g. c("vtkIOLegacy", "vtkCommonCore"). When NULL (the default) all available modules are included. When non-NULL, only the requested modules are linked, which reduces link time and produces a smaller downstream package when only part of VTK is used.

check

Whether to verify that every requested module is available in the detected VTK installation (see available_modules()) and fail with an actionable error when one is missing. Default TRUE.

Details

VTK_LIBS="$("${R_HOME}/bin/Rscript" --vanilla -e "rvtk::LdFlags()")"

On Windows the full set of VTK linker flags can exceed the 8 191-character command-line limit. Prefer LdFlagsFile() on Windows to write the flags to a response file instead.

Value

A single character string of linker flags, written to stdout (so that it can be captured by shell command substitution in configure) and returned invisibly.

See Also

use_rvtk()

Examples

flags <- LdFlags()

Write VTK linker flags to a response file

Description

On Windows the full set of VTK linker flags can exceed the 8 191-character Windows command-line limit, causing the linker to drop flags at the end of the list. This function writes the flags to a plain-text response file that the linker reads via the ⁠@file⁠ syntax, keeping the command line short.

Usage

LdFlagsFile(path, modules = NULL, check = TRUE, os_type = .Platform$OS.type)

Arguments

path

Path (relative to the package source root, i.e. where configure runs) to the response file to write on Windows, e.g. "src/vtk_libs.rsp". Ignored on non-Windows platforms.

modules

A character vector of VTK module names to link against, e.g. c("vtkIOLegacy", "vtkCommonCore"). When NULL (the default) all available modules are included. When non-NULL, only the requested modules are linked, which reduces link time and produces a smaller downstream package when only part of VTK is used.

check

Whether to verify that every requested module is available in the detected VTK installation (see available_modules()) and fail with an actionable error when one is missing. Default TRUE.

os_type

A string identifying the operating-system type, defaulting to .Platform$OS.type. Override to "windows" or "unix" in tests to exercise the Windows response-file branch without needing a Windows environment.

Details

Intended to be called from a downstream package's configure or configure.win script:

VTK_LIBS="$("${R_HOME}/bin/Rscript" --vanilla -e \
  "rvtk::LdFlagsFile('src/vtk_libs.rsp')")"
# VTK_LIBS is now the short string "@src/vtk_libs.rsp" on Windows,
# or the raw flags on macOS/Linux.

On Windows the flags are written to path and the function returns the ⁠@basename(path)⁠ token for the linker. On macOS and Linux, ld does not reliably support ⁠@file⁠ response files at the compiler-driver level, so no file is written and the raw flags are returned directly.

Value

Invisibly, the string to embed in configure (either ⁠@basename(path)⁠ on Windows or the raw flags on other platforms). The string is also written to stdout so that shell command substitution captures it.

See Also

use_rvtk()

Examples

rsp <- file.path(tempdir(), "vtk_libs.rsp")
ref <- LdFlagsFile(rsp)

Set up a downstream package to use rvtk

Description

A usethis-style helper that configures a downstream R package to link against VTK via rvtk. It performs the following steps:

  • Adds rvtk to the Imports field of DESCRIPTION.

  • Writes src/Makevars that queries compiler and linker flags at install time by calling tools/configure.R.

  • Writes src/Makevars.win with the Windows-specific ⁠$(shell ...)⁠ syntax that does the same.

  • Writes tools/configure.R that calls CppFlags() and LdFlagsFile() with the requested VTK modules.

  • Adds src/vtk_libs.rsp to .gitignore (it is generated at install time and must not be committed).

  • Creates R/rvtk_imports.R with a minimal ⁠@importFrom rvtk⁠ roxygen tag so that ⁠R CMD check⁠ does not complain about rvtk being listed in Imports without 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.

Usage

use_rvtk(modules = NULL, path = ".")

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 to LdFlagsFile() in the generated tools/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. the vtkParallelDIY / vtkIOCellGrid failures seen with older curated defaults), and passing a subset such as c("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.

Value

Invisibly, the normalised path to the package root. Called primarily for its side effects.

See Also

CppFlags(), LdFlagsFile()

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)
list.files(pkg, recursive = TRUE)
unlink(pkg, recursive = TRUE)

VTK version used by this package

Description

VTK version used by this package

Usage

VtkVersion()

Value

A character string with the VTK version detected at install time, e.g. "9.7.2".

Examples

VtkVersion()