Title: | Annotate Package Load Calls |
Version: | 0.2.4 |
Description: | Provides non-invasive annotation of package load calls such as \code{library()}, \code{p_load()}, and \code{require()} so that we can have an idea of what the packages we are loading are meant for. |
License: | MIT + file LICENSE |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.2 |
Imports: | dplyr, knitr, purrr, readr, rlang, rstudioapi, stringi, stringr, tibble, tidyr |
URL: | https://github.com/luisDVA/annotater, https://annotater.liomys.mx |
BugReports: | https://github.com/luisDVA/annotater/issues |
Suggests: | covr, rmarkdown, testthat |
VignetteBuilder: | knitr |
NeedsCompilation: | no |
Packaged: | 2025-07-14 18:07:53 UTC; luisd |
Author: | Luis D. Verde Arregoitia
|
Maintainer: | Luis D. Verde Arregoitia <luis@liomys.mx> |
Repository: | CRAN |
Date/Publication: | 2025-07-14 19:10:13 UTC |
annotater: Annotate Package Load Calls
Description
Provides non-invasive annotation of package load calls such as library()
, p_load()
, and require()
so that we can have an idea of what the packages we are loading are meant for.
Author(s)
Maintainer: Luis D. Verde Arregoitia luis@liomys.mx (ORCID)
Other contributors:
Juan Cruz Rodriguez [contributor]
Hadley Wickham [contributor]
See Also
Useful links:
Report bugs at https://github.com/luisDVA/annotater/issues
Vertical alignment of package annotations
Description
Internal helper function, based on 'unheadr::regex_valign“
Usage
align_annotations(
annot_string,
regex_ai = paste0("(?!\\))(?!\\s)(?=\\#\\sCRAN\\sv|",
"\\#\\sBiocon|\\#\\snot\\sinstall|", "\\#\\s\\[|\\#\\sPosit R)"),
sep_str = ""
)
Arguments
annot_string |
Character vector with annotated package calls. |
regex_ai |
Custom regular expression to match lines with package annotations. |
sep_str |
Whitespace separator. |
Value
A character vector with vertically aligned package calls.
Annotate active file
Description
Annotates package load calls in the active .R file
Usage
annotate_active_file()
Value
No return value, wraps [annotate_pkg_calls()] for access via Addin
Annotate loaded data in active file
Description
Annotates package load calls with loaded datasets in the active .R file
Usage
annotate_data_active_file()
Value
No return value, wraps [annotate_pkg_datasets()] for access via Addin
Annotate function calls
Description
Annotate function calls
Usage
annotate_fun_calls(string_og)
Arguments
string_og |
text string (script) with package load calls |
Value
text string with function call annotations. Will make note of packages not currently installed. Lines with existing comments or annotations are ignored by the regular expression that matches package names. Be aware that package-specific methods (e.g., print or summary methods) will be annotated too.
Examples
test_string <- c("library(boot)\nrequire(lattice)\ncanonical.theme()")
cat(annotate_fun_calls(test_string))
Annotate function calls in active file
Description
Annotates package load calls with the used functions of each package in the active .R file
Usage
annotate_fun_calls_active_file()
Value
No return value, wraps [annotate_fun_calls()] for access via Addin
Annotate package calls
Description
Annotate package calls
Usage
annotate_pkg_calls(string_og, pkg_field = "Title")
Arguments
string_og |
Text string (script) with package load calls. |
pkg_field |
Field from package description to retrieve, defaults to "Title" |
Value
Text string with package Title annotations. Will make note of packages not currently installed.
Examples
test_string <- c("library(boot)\nrequire(tools)")
annotate_pkg_calls(test_string)
Annotate package datasets
Description
Annotate package datasets
Usage
annotate_pkg_datasets(string_og)
Arguments
string_og |
text string (script) with package load calls |
Details
No support for pacman package loading at this time.
Value
text string with annotations for datasets loaded from packages explicitly, lazily, or through name-spacing. Will make note of packages not currently installed. Lines with existing comments or annotations are ignored.
Examples
test_string <- c("library(tidyr)\nlibrary(purrr)\ndata(construction)\nsummary(fish_encounters)")
annotate_pkg_datasets(test_string)
Annotate R Version
Description
Annotate R Version
Usage
annotate_r_version()
Annotate repository sources
Description
Annotate repository sources
Usage
annotate_repo_source(string_og)
Arguments
string_og |
text string (script) with package load calls |
Value
text string with package repository source annotations. Will make note of packages not currently installed. Lines with existing comments or annotations are ignored by the regular expression that matches package names. Also ignores base packages. Local installs now annotated as such.
Examples
test_string <- c("library(knitr)\nrequire(datasets)")
annotate_repo_source(test_string)
Annotate repositories in active file
Description
Annotates package load calls with repository details in the active .R file
Usage
annotate_repos_active_file()
Value
No return value, wraps [annotate_repo_source()] for access via Addin
Annotate package titles and repository sources
Description
Annotate package titles and repository sources
Usage
annotate_repostitle(string_og)
Arguments
string_og |
Text string (script) with package load calls. |
Details
Some annotations may be long, check for possible line breaks introduced into your script.
Value
Text string with package titles and package repository source annotations. Will make note of packages not currently installed. Lines with existing comments or annotations are ignored by the regular expression that matches package names. Also ignores base packages.
Examples
test_string <- c("library(knitr)\nrequire(datasets)")
annotate_repostitle(test_string)
Annotate titles and repositories in active file
Description
Annotates package load calls with package titles and repository details in the active .R file
Usage
annotate_repostitle_active()
Value
No return value, wraps [annotate_repostitle()] for access via Addin
Annotate script
Description
Annotate script
Usage
annotate_script(script_file, pkg_field = "Title")
Arguments
script_file |
Path to an R script. |
pkg_field |
Field from package description to retrieve, defaults to "Title". |
Value
Prints the annotated script to the console.
Check if packages are installed
Description
Check if packages are installed
Usage
check_pkgs(pkgvec)
Arguments
pkgvec |
Vector of package names |
Value
A data frame with installation status for packages in the input text.
Expand metapackages
Description
Expand metapackages
Usage
expand_metapackages(string_og)
Arguments
string_og |
text string (script) with package load calls |
Value
Text string with metapackage load calls replaced by multiple separate calls to the core packages that make up the metapackage. Core packages will be fenced in four commenting symbols and the order follows the attachment order from each metapackage. Will make note of metapackages not currently installed.
Examples
test_string <- c("library(tidyverse)")
expand_metapackages(test_string)
Expand metapackages in active file
Description
Replaces metapackage load calls in the active .R file with multiple separate calls to its core packages.
Usage
expand_metapackages_active_file()
Value
No return value, wraps [expand_metapackages()] for access via Addin
Query data from packages
Description
Query data from packages
Usage
get_pkg_datasets(inst_pkgs)
Arguments
inst_pkgs |
Vector of package names |
Value
A data frame with all the bundled data from the specified packages.
Match package names
Description
Match package names
Usage
match_pkg_names(string_og)
Arguments
string_og |
Text string (script) with package load calls. |
Value
A tibble with the package load calls and package names.
Examples
test_string <- c("library(boot)\nrequire(Matrix)")
match_pkg_names(test_string)
Retrieve Package version
Description
Internal helper function.
Usage
pkg_version(pkgs_col)
Arguments
pkgs_col |
Package name. |
Value
A character vector with the package version.
Retrieve repo details
Description
Internal helper function.
Usage
repo_details(pkgs_col)
Arguments
pkgs_col |
Name of variable with the non-CRAN repos. |
Value
A character vector of user names and repository names.