Convert Citation Keys to Inline References
Source:R/xct_keys_to_inline.R
, R/xct_keys_to_inline_table_col.R
xct_keys_to_inline.Rd
This function processes a block of text containing citation keys (e.g., @doe2020
)
and converts them to inline references using Pandoc. The function supports
custom bibliography and CSL (Citation Style Language) files.
This function applies the xct_keys_to_inline transformation to a specified column in a data frame. It validates the inputs, checks that the specified column exists in the data frame, and replaces citation keys with inline citations.
Usage
xct_keys_to_inline(text, path_bib, csl_file = NULL)
xct_keys_to_inline_table_col(
dat = NULL,
col_format = NULL,
path_bib = "references.bib"
)
Arguments
- text
A character vector containing text with citation keys (e.g.,
@doe2020
).- path_bib
A file path to the bibliography file (
.bib
) used for citation keys. Defaults to"references.bib"
in the current working directory.- csl_file
A string specifying the path to the CSL file (e.g.,
apa.csl
). Default isNULL
, which uses Pandoc's default citation style.- dat
A data frame containing the column to transform.
- col_format
A string specifying the name of the column to transform.
Value
A character vector with inline references replacing the citation keys.
A data frame with the specified column transformed.
See also
Other cite:
xct_assemble()
,
xct_bib_keys_missing()
,
xct_format()
,
xct_format_single()
,
xct_keys_extract()
,
xct_keys_to_xref()
Examples
# Path to a BibTeX file included in the package
path_bib <- system.file("extdata", "references.bib", package = "xciter")
# Example data frame
dat <- data.frame(
id = 1:3,
bib_keys = c(
"Outside block quotes @busch_etal2011LandscapeLevelModela and in [@woll_etal2017SalmonEcological]",
"This is many [@busch_etal2011LandscapeLevelModela; @woll_etal2017SalmonEcological; @kirsch_etal2014Fishinventory]",
"this is a failed key @key3")
)
# Process the data frame
result <- xct_keys_to_inline_table_col(dat, col_format = "bib_keys", path_bib = path_bib)
result
#> id
#> 1 1
#> 2 2
#> 3 3
#> bib_keys
#> 1 Outside block quotes Busch et al. (2011) and in (Woll, Albert, and Whited 2017)
#> 2 This is many (Busch et al. 2011; Woll, Albert, and Whited 2017; Kirsch, Buckwalter, and Reed 2014)
#> 3 this is a failed key (key3?)