Scans the Zig source of the package with scan_exports(), renders the
bindings with render_bindings(), and writes them: the Zig manifest
src/rzig/framework/generated/manifest.zig, the R wrappers
R/rzig-wrappers.R, a managed block in NAMESPACE, and a help page
man/<name>.Rd for every exported function, written from its Zig doc
comment (the first paragraph is the title and description; @param,
@return, @examples, @details, @seealso, @references and @note
fill the matching sections). Lines of NAMESPACE outside the block and help
pages that rzig did not write are kept. The function is pure R; no Zig
compiler is needed.
Arguments
- path
Path to a package previously initialized with
use_rzig().
Value
The rzig_bindings object that was written,
with the element files naming the files written, invisibly.
Details
When roxygen2 generates NAMESPACE (its first line is
# Generated by roxygen2: do not edit by hand), the useDynLib directive
is written into R/rzig-wrappers.R as a @rawNamespace tag, and
NAMESPACE receives the same lines roxygen2 writes from the tags. The
package then works whichever of document(), roxygen2::roxygenise() or
devtools::document() ran last; run document() after changing an
exported Zig signature so that the wrappers follow it.
roxygen2 then writes the help pages from the wrappers, and document()
writes none.
Run document() after every change to an exported Zig signature or its
documentation comment, and before installing the package.
Examples
package_path <- tempfile("rzig-document-", 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 <- document(package_path)
#> Generated RZig bindings for examplepkg: 1 exported function
bindings$files
#> [1] "src/rzig/framework/generated/manifest.zig"
#> [2] "R/rzig-wrappers.R"
#> [3] "NAMESPACE"
#> [4] "man/hello_zig.Rd"
cat(readLines(file.path(package_path, "NAMESPACE")), sep = "\n")
#> # Generated by rzig::document(): begin
#> useDynLib("examplepkg",
#> hello_zig_ = "hello_zig"
#> )
#> export("hello_zig")
#> # Generated by rzig::document(): end
unlink(package_path, recursive = TRUE)