Skip to contents

An install.packages() call in analysis code installs software on whoever runs the script, without asking – a portability and security concern raised in issue #398: at minimum it is disruptive (unexpected installs, network access, a package version the author didn't test against), and at worst a security risk if it points at a private/ untrusted repository. Best practice is to document required packages (a README, a renv.lock/DESCRIPTION) rather than install them from inside the analysis code itself. This scans the (comment-free) code for install.packages(...) calls and returns one row per call, with the argument as written. Only a LIVE call is ever seen here: a commented-out #install.packages(...) is invisible to this function by construction, the same way code_setwd() never sees a commented-out setwd() – both are only ever called on code_remove_comments()'s output. R-only (the construct is R's; other languages have their own package managers, which this does not scan).

Usage

code_install_packages(code_text)

Arguments

code_text

the code text for a single file (character vector), ideally comment-free (as produced by code_remove_comments())

Value

a data frame with columns install_packages_call (the install.packages(...) text as written) and line (its line number). Empty frame when none are found.

Examples

code_text <- c(
  "install.packages('ggplot2')",
  "library(ggplot2)"
)
code_install_packages(code_text)
#> # A tibble: 1 × 2
#>   install_packages_call        line
#>   <chr>                       <int>
#> 1 install.packages('ggplot2')     1