Version: 0.1.1
Title: Automatic Generation of @importFrom Tags
Description: A toolbox to read all R files inside a package and automatically generate @importFrom 'roxygen2' tags in the right place. Includes a 'shiny' application to review the changes before applying them.
License: GPL-3
URL: https://github.com/DanChaltiel/autoimport, https://danchaltiel.github.io/autoimport/
BugReports: https://github.com/DanChaltiel/autoimport/issues
Depends: R (≥ 3.6.0)
Imports: cli, desc, diffviewer, digest, dplyr, fs, glue, purrr, readr, rlang, shiny, stringr, tibble, tidyr, utils
Suggests: callr, covr, devtools, knitr, pkgload, rstudioapi, testthat (≥ 3.0.0), tidyverse
Encoding: UTF-8
RoxygenNote: 7.3.2
Config/testthat/edition: 3
NeedsCompilation: no
Packaged: 2025-02-01 09:31:57 UTC; Dan
Author: Dan Chaltiel ORCID iD [aut, cre]
Maintainer: Dan Chaltiel <dan.chaltiel@gmail.com>
Repository: CRAN
Date/Publication: 2025-02-03 12:00:02 UTC

autoimport: Automatic Generation of @importFrom Tags

Description

A toolbox to read all R files inside a package and automatically generate @importFrom 'roxygen2' tags in the right place. Includes a shiny application to review the changes before applying them.

Author(s)

Maintainer: Dan Chaltiel dan.chaltiel@gmail.com (ORCID)

See Also

Useful links:


Automatically compute ⁠@importFrom⁠ tags

Description

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 ⁠@importFrom⁠ dispatched 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:

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


Decision management

Description

Opens a Shiny app that shows a visual diff of each modified file.

Usage

import_review(
  source_path = "R/",
  output_path = get_target_dir(),
  background = getOption("autoimport_background", FALSE)
)

Arguments

source_path

path to the original R files

output_path

path to the updated R files

background

whether to run the app in a background process. Default to getOption("autoimport_background", FALSE).

Value

nothing if background==FALSE, the (callr::process) object if background==TRUE

Warning

Beware that using background=TRUE can bloat your system with multiple R session!
You should probably kill the process when you are done:

p=import_review(background=TRUE)
p$kill()

Source

inspired by testthat::snapshot_review()


Update the IMPORTLIST file

Description

Update the IMPORTLIST file, which forces the import of some packages without asking.

Usage

update_importlist(imports, path = NULL)

get_importlist(path = NULL)

Arguments

imports

a list of imports with ⁠key=function⁠ and value=package

path

path to the IMPORTLIST file

Value

nothing