Title: | Annotate Package Load Calls |
---|---|
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. |
Authors: | Luis D. Verde Arregoitia [aut, cre] , Juan Cruz Rodriguez [ctb], Hadley Wickham [ctb] |
Maintainer: | Luis D. Verde Arregoitia <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.3.9000 |
Built: | 2024-11-08 05:59:33 UTC |
Source: | https://github.com/luisdva/annotater |
Internal helper function, based on 'unheadr::regex_valign“
align_annotations( annot_string, regex_ai = paste0("(?!\\))(?!\\s)(?=\\#\\sCRAN\\sv|", "\\#\\sBiocon|\\#\\snot\\sinstall|", "\\#\\s\\[|\\#\\sPosit R)"), sep_str = "" )
align_annotations( annot_string, regex_ai = paste0("(?!\\))(?!\\s)(?=\\#\\sCRAN\\sv|", "\\#\\sBiocon|\\#\\snot\\sinstall|", "\\#\\s\\[|\\#\\sPosit R)"), sep_str = "" )
annot_string |
Character vector with annotated package calls. |
regex_ai |
Custom regular expression to match lines with package annotations. |
sep_str |
Whitespace separator. |
A character vector with vertically aligned package calls.
Annotates package load calls in the active .R file
annotate_active_file()
annotate_active_file()
No return value, wraps [annotate_pkg_calls()] for access via Addin
Annotates package load calls with loaded datasets in the active .R file
annotate_data_active_file()
annotate_data_active_file()
No return value, wraps [annotate_pkg_datasets()] for access via Addin
Annotate function calls
annotate_fun_calls(string_og)
annotate_fun_calls(string_og)
string_og |
text string (script) with package load calls |
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.
test_string <- c("library(boot)\nrequire(lattice)\ncanonical.theme()") cat(annotate_fun_calls(test_string))
test_string <- c("library(boot)\nrequire(lattice)\ncanonical.theme()") cat(annotate_fun_calls(test_string))
Annotates package load calls with the used functions of each package in the active .R file
annotate_fun_calls_active_file()
annotate_fun_calls_active_file()
No return value, wraps [annotate_fun_calls()] for access via Addin
Annotate package calls
annotate_pkg_calls(string_og, pkg_field = "Title")
annotate_pkg_calls(string_og, pkg_field = "Title")
string_og |
Text string (script) with package load calls. |
pkg_field |
Field from package description to retrieve, defaults to "Title" |
Text string with package Title annotations. Will make note of packages not currently installed.
test_string <- c("library(boot)\nrequire(tools)") annotate_pkg_calls(test_string)
test_string <- c("library(boot)\nrequire(tools)") annotate_pkg_calls(test_string)
Annotate package datasets
annotate_pkg_datasets(string_og)
annotate_pkg_datasets(string_og)
string_og |
text string (script) with package load calls |
No support for pacman package loading at this time.
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.
test_string <- c("library(tidyr)\nlibrary(purrr)\ndata(construction)\nsummary(fish_encounters)") annotate_pkg_datasets(test_string)
test_string <- c("library(tidyr)\nlibrary(purrr)\ndata(construction)\nsummary(fish_encounters)") annotate_pkg_datasets(test_string)
Annotate repository sources
annotate_repo_source(string_og)
annotate_repo_source(string_og)
string_og |
text string (script) with package load calls |
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.
test_string <- c("library(boot)\nrequire(lattice)") annotate_repo_source(test_string)
test_string <- c("library(boot)\nrequire(lattice)") annotate_repo_source(test_string)
Annotates package load calls with repository details in the active .R file
annotate_repos_active_file()
annotate_repos_active_file()
No return value, wraps [annotate_repo_source()] for access via Addin
Annotate package titles and repository sources
annotate_repostitle(string_og)
annotate_repostitle(string_og)
string_og |
Text string (script) with package load calls. |
Some annotations may be long, check for possible line breaks introduced into your script.
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.
test_string <- c("library(boot)\nrequire(lattice)") annotate_repostitle(test_string)
test_string <- c("library(boot)\nrequire(lattice)") annotate_repostitle(test_string)
Annotates package load calls with package titles and repository details in the active .R file
annotate_repostitle_active()
annotate_repostitle_active()
No return value, wraps [annotate_repostitle()] for access via Addin
Annotate script
annotate_script(script_file, pkg_field = "Title")
annotate_script(script_file, pkg_field = "Title")
script_file |
Path to an R script. |
pkg_field |
Field from package description to retrieve, defaults to "Title". |
Prints the annotated script to the console.
Check if packages are installed
check_pkgs(pkgvec)
check_pkgs(pkgvec)
pkgvec |
Vector of package names |
A data frame with installation status for packages in the input text.
Expand metapackages
expand_metapackages(string_og)
expand_metapackages(string_og)
string_og |
text string (script) with package load calls |
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.
test_string <- c("library(tidyverse)") expand_metapackages(test_string)
test_string <- c("library(tidyverse)") expand_metapackages(test_string)
Replaces metapackage load calls in the active .R file with multiple separate calls to its core packages.
expand_metapackages_active_file()
expand_metapackages_active_file()
No return value, wraps [expand_metapackages()] for access via Addin
Query data from packages
get_pkg_datasets(inst_pkgs)
get_pkg_datasets(inst_pkgs)
inst_pkgs |
Vector of package names |
A data frame with all the bundled data from the specified packages.
Match package names
match_pkg_names(string_og)
match_pkg_names(string_og)
string_og |
Text string (script) with package load calls. |
A tibble with the package load calls and package names.
test_string <- c("library(boot)\nrequire(Matrix)") match_pkg_names(test_string)
test_string <- c("library(boot)\nrequire(Matrix)") match_pkg_names(test_string)
Internal helper function.
pkg_version(pkgs_col)
pkg_version(pkgs_col)
pkgs_col |
Package name. |
A character vector with the package version.
Internal helper function.
repo_details(pkgs_col)
repo_details(pkgs_col)
pkgs_col |
Name of variable with the non-CRAN repos. |
A character vector of user names and repository names.