The function automatically detects the current R script file (works best in RStudio), parses the code to identify function calls, determines which packages they belong to, and creates a summary of all non-base R packages used in the script. It handles both namespace-qualified function calls (e.g., dplyr::filter) and regular function calls, while filtering out base R functions and control structures.

extract_package_details(ignore_comments = TRUE)

Arguments

ignore_comments

Logical. If TRUE (default), ignores function calls within commented code (both R comments starting with # and HTML/XML comments ). If FALSE, extracts functions from all code including commented sections.

Value

A data frame with the following columns:

package_name

Character. Name of the package

functions_called

Character. Comma-separated list of functions called from this package

package_version

Character. Version number of the installed package

package_citation

Character. Formatted citation for the package

Details

This function analyses the current file (an R script, Rmd or qmd file) to extract information about all functions called within the code, identifies their associated packages, and returns a summary of packages used with version and citation information.

Note

  • Works best when run from RStudio with an active source file

  • Requires that referenced packages are already loaded/installed

  • Will not detect functions called through indirect methods (e.g., do.call())

Examples

if (FALSE) { # \dontrun{
# Run this function from within an R script to analyze its dependencies
package_info <- extract_package_details()

# Include functions from commented code
package_info_all <- extract_package_details(ignore_comments = FALSE)
print(package_info)
} # }