Produces the three texts that document() writes into a package, without
writing anything: the Zig manifest that registers the exported functions,
the R wrappers that call them, and the NAMESPACE block that resolves the
native symbols. Use the function to inspect what document() will
generate.
Usage
render_bindings(
exports,
package = attr(exports, "package", exact = TRUE),
roxygen = FALSE
)Arguments
- exports
An object returned by
scan_exports().- package
The package name; by default taken from
exports.- roxygen
Render for a package whose
NAMESPACEroxygen2 generates: the wrappers then carry theuseDynLibdirective as a@rawNamespacetag, andnamespaceholds the lines roxygen2 writes for them.
Value
An object of class rzig_bindings: a list with the character
strings manifest (src/rzig/framework/generated/manifest.zig),
wrappers (R/rzig-wrappers.R) and namespace (the generated
NAMESPACE block, or with roxygen = TRUE the NAMESPACE lines that
roxygen2 writes for the wrappers), and the exports the texts were
rendered from.
Examples
package_path <- tempfile("rzig-render-", tmpdir = tempdir())
dir.create(package_path)
writeLines(c("Package: examplepkg", "Version: 0.0.1"),
file.path(package_path, "DESCRIPTION"))
use_rzig(package_path)
#> Generated RZig bindings for examplepkg: 1 exported function
#> Created RZig scaffold for package examplepkg
bindings <- render_bindings(scan_exports(package_path))
cat(bindings$wrappers)
#> # Generated by rzig::document(). Do not edit.
#>
#> #' Return a friendly greeting.
#> #' @param name A name to greet.
#> #' @return A character string.
#> #' @examples
#> #' hello_zig("R")
#> #'
#> #' @export
#> hello_zig <- function(name) {
#> .Call(hello_zig_, name)
#> }
cat(bindings$namespace)
#> # Generated by rzig::document(): begin
#> useDynLib("examplepkg",
#> hello_zig_ = "hello_zig"
#> )
#> export("hello_zig")
#> # Generated by rzig::document(): end
unlink(package_path, recursive = TRUE)