Skip to contents

Automatically read all R files and compute appropriate @importFrom tags in the roxygen headers. Choose which tags to add in the shiny app import_review() afterward.

Usage

autoimport(
  root = ".",
  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.

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).