Package 'pakret'

Title: Cite 'R' Packages on the Fly in 'R Markdown' and 'Quarto'
Description: References and cites 'R' and 'R' packages on the fly in 'R Markdown' and 'Quarto'. 'pakret' provides a minimalistic API that generates preformatted citations of 'R' and 'R' packages, and adds their reference to a '.bib' file directly from within your document.
Authors: Arnaud Gallou [aut, cre, cph]
Maintainer: Arnaud Gallou <[email protected]>
License: GPL (>= 3)
Version: 0.2.2.9000
Built: 2024-10-23 11:13:59 UTC
Source: https://github.com/arnaudgallou/pakret

Help Index


Cite R or an R package

Description

Creates a preformatted citation of R or an R package. This function should normally only be used in an R Markdown or Quarto document, in which case pkrt() automatically references the cited package in the first (by default) .bib file specified in the YAML header if no references of the package already exist.

Usage

pkrt(pkg)

Arguments

pkg

Name of the package to cite.

Value

A character string.

Examples

pkrt("pakret")

pkrt("R")

Cite a collection of R packages

Description

Creates a list of package citations that can be turned into a character string or data frame. This function should normally only be used in an R Markdown or Quarto document, in which case pkrt_list() automatically references the cited packages in the first (by default) .bib file specified in the YAML header if no references of the packages already exist.

Usage

pkrt_list(...)

Arguments

...

Character vectors, separated by commas, of packages to cite.

Details

This function automatically discards duplicate and base packages. You can use pkrt_list() in combination with renv::dependencies() to cite all the packages used in a project or directory.

Value

A list of package citations with S3 class pkrt_list.

Examples

# Create a list of citations
citations <- pkrt_list("pakret", "readr", "withr")

# You can then turn the citations into a character string
paste(citations, collapse = ", ")

# Or a data frame
as.data.frame(citations)

Configure pakret's settings

Description

This function allows you to configure pakret's settings, e.g. to customize citation templates or control which .bib file to save references to.

Usage

pkrt_set(...)

Arguments

...

Key-value pairs, separated by commas, of parameters to set. See details.

Details

Valid parameters are:

  • bib
    ⁠<character|numeric> = 1L⁠
    Name or index of the .bib file to save references to.

  • pkg
    ⁠<character> = "the ':pkg' package version :ver [:ref]"⁠
    Template used to cite a package.

  • pkg_list
    ⁠<character> = "':pkg' v. :ver [:ref]"⁠
    Template used in pkrt_list().

  • r
    ⁠<character> = "R version :ver [:ref]"⁠
    Template used to cite R.

New settings only apply to citations that come after pkrt_set(). This means that you can redefine the same settings multiple times in the same document to alter pakret's behavior for a few specific citations only.

Use NULL to reset a parameter to its default value.

Value

This function is called for its side-effect. It returns no value.

Examples

pkrt_set(pkg = ":pkg (v. :ver) :ref")
pkrt("pakret")

# `NULL` resets parameters to their default value
pkrt_set(pkg = NULL)
pkrt("pakret")