R/libr_used.R

libr_used <- \(script = NULL) {
  if (is.null(script)) script <- rstudioapi::getActiveDocumentContext()$path
  packages <-
      sub("package:", "",
          grep("package",
               summary(
                 script |>
                   NCmisc::list.functions.in.file()
               )[, 1] |>
                 names()
               , value = T)
      )

    installed_packages <- installed.packages()[, "Package"]
    packages <- intersect(packages, installed_packages)

  return(packages)
}

Try the nolock package in your browser

Any scripts or data that you put into this service are public.

nolock documentation built on Nov. 15, 2023, 9:07 a.m.