| Title: | Integrated Code Chunk Anchoring and Referencing for R Markdown Documents |
|---|---|
| Description: | A streamlined cross-referencing system for R Markdown documents generated with 'knitr'. R Markdown is an authoring format for generating dynamic content from R. 'kfigr' provides a hook for anchoring code chunks and a function to cross-reference document elements generated from said chunks, e.g. figures and tables. |
| Authors: | Michael C Koohafkan [aut, cre] |
| Maintainer: | Michael C Koohafkan <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 1.2.1 |
| Built: | 2026-05-31 09:11:58 UTC |
| Source: | https://github.com/mkoohafkan/kfigr |
A streamlined cross-referencing system for R Markdown documents
generated with 'knitr'. It provides the chunk hook anchor
and a cross-referencing function figr. See the vignette to
get started.
Retrieves diagnostics such as the anchor index and history. Use for code verification and troubleshooting. Also used internally by kfigr.
anchors(tag)anchors(tag)
tag |
Optional specification of return type. |
If tag = "index", a dataframe listing all anchored chunks. If
tag = "history", a dataframe listing all references made, in order.
If the value of tag matches a specific type, all references
of that type are provided in a list. If tag is missing, all
references of all types are provided in a nested list.
figr("foo", type="figure") figr("bar", type="table") figr("test", type="figure") anchors()figr("foo", type="figure") figr("bar", type="table") figr("test", type="figure") anchors()
Reference a code chunk.
figr(label, prefix, link, type)figr(label, prefix, link, type)
label |
The code chunk label. |
prefix |
Logical: return the prefix (chunk type) along with the rank. |
link |
### Logical: Place an HTML link to the anchor? |
type |
The type of the referenced chunk. |
A text or url reference to the code chunk.
figr("test", type="reference") figr("test") figr("test", TRUE, link=FALSE) if(interactive()){ require(knitr) opts_knit$set(kfigr.prefix=TRUE, kfigr.link=TRUE) figr("test") }figr("test", type="reference") figr("test") figr("test", TRUE, link=FALSE) if(interactive()){ require(knitr) opts_knit$set(kfigr.prefix=TRUE, kfigr.link=TRUE) figr("test") }
knitr hook functions are called when the corresponding chunk options
are not NULL to do additional jobs beside the R code in chunks.
kfigr provides the hook "anchor" which adds an HTML anchor tag
immediately above a code chunk.
hook_anchor(before, options, envir)hook_anchor(before, options, envir)
before, options, envir
|
see references |
the function hook_anchor is set as a hook in knitr when
kfigr is attached (and removed when kfigr is detached). It
writes an HMTL anchor tag directly above a code chunk in the form
<a name="chunk-name"></a> where chunk-name is the chunk
label contained in options$label.
http://yihui.org/knitr/hooks#chunk-hooks
## Not run: require(knitr) knit_hooks$set(anchor = hook_anchor) # then in code chunks, use e.g. the option anchor = "figure" ## End(Not run)## Not run: require(knitr) knit_hooks$set(anchor = hook_anchor) # then in code chunks, use e.g. the option anchor = "figure" ## End(Not run)
(Internal) index a chunk. Should not be called by the user directly.
index(label, type)index(label, type)
label |
The chunk label. |
type |
The type of chunk to be indexed. |
The rank of the indexed chunk.