Package {rvtk}


Title: Bindings for the Visualization Toolkit ('VTK')
Version: 0.2.0
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 are provided for macOS, Linux, and Windows; on Windows a shared-DLL build is available via 'VTK_LINK_TYPE=shared'.
License: MIT + file LICENSE
Encoding: UTF-8
URL: https://github.com/astamm/rvtk, https://astamm.github.io/rvtk/
BugReports: https://github.com/astamm/rvtk/issues
NeedsCompilation: no
Suggests: cli, knitr, quarto, tinytest
Config/roxygen2/version: 8.1.1
Config/roxygen2/markdown: TRUE
VignetteBuilder: quarto
Packaged: 2026-11-17 22:17:30 UTC; stamm-a
Author: Aymeric Stamm ORCID iD [aut, cre, cph]
Maintainer: Aymeric Stamm <aymeric.stamm@cnrs.fr>
Repository: CRAN
Date/Publication: 2026-11-18 09:50:07 UTC

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)

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 avoids pulling in object files that reference symbols from modules outside the selected set when using the pre-built static bundle.

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, 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 avoids pulling in object files that reference symbols from modules outside the selected set when using the pre-built static bundle.

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)

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()

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:

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 = c("vtkIOLegacy", "vtkIOXML", "vtkIOXMLParser", "vtkIOCore", "vtkIOGeometry",
    "vtkFiltersCore", "vtkFiltersGeneral", "vtkFiltersGeometry", "vtkFiltersModeling",
    "vtkFiltersExtraction", "vtkCommonCore", "vtkCommonDataModel",
    "vtkCommonExecutionModel", "vtkCommonMath", "vtkCommonMisc", "vtkCommonSystem",
    "vtkCommonTransforms", "vtksys"),
  path = "."
)

Arguments

modules

A character vector of VTK module names to link against. These are passed to LdFlagsFile() in the generated tools/configure.R, restricting linking to only the modules the downstream package needs. Defaults to a standard set covering the common I/O, filtering, core, and data-model modules bundled with rvtk.

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)