Automatically read all R files and compute appropriate @importFrom tags in the roxygen2 headers.
The tags can be added to the source files using the import_review() shiny app afterward.
Usage
autoimport(
root = ".",
...,
location = c("function", "package"),
files = get_R_dir(root),
namespace_file = "NAMESPACE",
description_file = "DESCRIPTION",
use_cache = TRUE,
ignore_package = TRUE,
verbose = 2
)Arguments
- root
Path to the root of the package.
- ...
unused
- location
Whether to add
@importFromdispatched above each function, or centralized at the package level.- files
Files to read. Default to the
R/folder.- namespace_file
Path to the NAMESPACE file
- description_file
Path to the DESCRIPTION file
- use_cache
Whether to use the cache system. Can only be "read" or "write".
- ignore_package
Whether to ignore files ending with
-package.R- verbose
The higher, the more output printed. May slow the process a bit.
Value
Mostly used for side effects. Invisibly returns a dataframe summarizing the function imports, with input arguments as attributes.
Limitations
Autoimport is based on utils::getSrcref() and share the same limits.
Therefore, some function syntaxes are not recognized and autoimport will try to remove their @importFrom from individual functions:
Operators (
@importFrom dplyr %>%,@importFrom rlang :=, ...)Functions called by name (e.g.
sapply(x, my_fun))Functions used inside strings (e.g.
glue("my_fun={my_fun(x)}"))
To keep them imported, you should either use a prefix (pkg::my_fun) or import them in your package-level documentation, as this file is ignored by default (with ignore_package=TRUE).