spot_pkgs {funspotr} | R Documentation |
Spot Packages
Description
Extract all pkg
called in either library(pkg)
, require(pkg)
requireNamespace("pkg")
or pkg::fun()
. Will not identify packages loaded
in other ways not typically done in interactive R scripts (e.g. relying on a
DESCRIPTION file for a pkg or something like source("lib-calls.R")
).
Inspiration: blogdown#647.
Usage
spot_pkgs(
file_path,
show_explicit_funs = FALSE,
copy_local = TRUE,
as_yaml_tags = FALSE
)
Arguments
file_path |
String of path to file of interest. |
show_explicit_funs |
In cases where a function is called explicitly,
show both the package dependency and the function together. For example a
script containing |
copy_local |
Logical, default is |
as_yaml_tags |
Logical, default is |
Details
In cases where show_explicit_funs = TRUE
and there are explicit calls in
the package, "pkg:fun" is returned instead.
Packages are extracted solely based on text – not whether the package actually exists or not. Hence even packages that you do not have installed on your machine but show-up in the script will be returned in the character vector.
Value
Character vector of all packages loaded in file.
See Also
spot_pkgs_used()
, spot_pkgs_from_description()
,
spot_pkgs_files()
, renv::dependencies()
Examples
library(funspotr)
file_lines <- "
library(dplyr)
require(tidyr)
library(madeUpPkg)
as_tibble(mpg) %>%
group_by(class) %>%
nest() %>%
mutate(stats = purrr::map(data,
~lm(cty ~ hwy, data = .x)))
made_up_fun()
"
file_output <- tempfile(fileext = ".R")
writeLines(file_lines, file_output)
spot_pkgs(file_output)
# To view `purrr::map` as an explicit call
spot_pkgs(file_output, show_explicit_funs = TRUE)
# To output for blogdown post YAML header tags
cat(spot_pkgs(file_output, as_yaml_tags = TRUE))