Package 'kfigr'

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: 2025-01-01 05:06:44 UTC
Source: https://github.com/mkoohafkan/kfigr

Help Index


Integrated Code Chunk Anchoring and Referencing for R Markdown Documents

Description

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.


Anchor Information

Description

Retrieves diagnostics such as the anchor index and history. Use for code verification and troubleshooting. Also used internally by kfigr.

Usage

anchors(tag)

Arguments

tag

Optional specification of return type. tag = "index" returns a dataframe listing the chunk labels, asigned types and index numbers. tag = "history" returns a dataframe listing all reference calls, in order.

Value

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.

Examples

figr("foo", type="figure")
figr("bar", type="table")
figr("test", type="figure")
anchors()

Code Chunk Reference

Description

Reference a code chunk.

Usage

figr(label, prefix, link, type)

Arguments

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.

Value

A text or url reference to the code chunk.

Examples

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")
}

Anchor Chunk Hook Extension for package:knitr

Description

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.

Usage

hook_anchor(before, options, envir)

Arguments

before, options, envir

see references

Details

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.

References

http://yihui.org/knitr/hooks#chunk-hooks

See Also

figr, anchors

Examples

## Not run: 
require(knitr)
knit_hooks$set(anchor = hook_anchor)
# then in code chunks, use e.g. the option anchor = "figure"

## End(Not run)

Chunk Indexing

Description

(Internal) index a chunk. Should not be called by the user directly.

Usage

index(label, type)

Arguments

label

The chunk label.

type

The type of chunk to be indexed.

Value

The rank of the indexed chunk.

See Also

figr, anchors