knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
set.seed(123)

packtrack

Lifecycle: experimental CRAN status

The goal of {packtrack} is to track the usage of R packages on your system.

This package is highly experimental and far from being complete.

The main motivation for this project is that R packages tend to accumulate beyond desire. If you install a package to try out, it usually comes with new dependencies that will be installed alongside with it. Thus, unless you are very meticulous or use particular systems such as {packrat}, you will quickly loose track of what you actually need to keep on your system. Installed packages do not take much space on the disk, but one major caveat of keeping unnecessary dependencies is that your update time will increase with the number of installed R packages.

By tracking which packages you are using, {packtrack} will help you identify which are the ones you don't use, so that you can remove them.

The package can also be used to study which dependencies are used in practice during various workflow, which can help developers identify which dependencies they could move from Import to Suggests.

Installation

You can install this package using {remotes} (or {devtools}):

remotes::install_github("nathan-russell/hashmap") ## dependency needed
remotes::install_github("courtiol/packtrack")

Example

library(packtrack) ## tracking begins

packtrack_view() ## no packages used yet

library(stringr) ## we load stringr

packtrack_view() ## stringr has been imported

str_c("foo", "bar") ## we use a function not using dependencies

packtrack_view() ## no package has been used

str_glue("foo", "bar") ## we use a function using dependencies

packtrack_view() ## several packages have been used

packtrack_view(previously_loaded = TRUE) ## also includes the packages loaded before tracking

all_pkg <- packtrack_view(non_used = TRUE) ## also includes all other packages installed on the system

sum(all_pkg$times_loaded != 0) ## number of packages used during this session

sum(all_pkg$times_loaded == 0) ## number of packages not used during this session

packtrack_stop() ## tracking stops

detach(package:stringr) ## detach stringr

packtrack_start() ## tracking starts anew

packtrack_view() ## no packages used yet

packtrack_pause() ## tracking pauses

library(stringr)

packtrack_resume() ## tracking resumes

packtrack_view() ## tidyr has not been tracked

What to expect in the future

CRAN release?

Under the current implementation, the tracking procedure implies overriding a base function, which is against CRAN policies (for good reasons). It would be possible to do similar things without overriding any function, but that would imply to run a loop in the background. Such a loop would be needed to regularly check which namespaces have been loaded and update the list of packages that have been used. The result would be almost the same, but such a loop would use more system resources and one difference is that the tracking would also not be able to count how many imports of the same package have been performed (but perhaps, this information is not really interesting anyhow...).

Help \& feedbacks wanted!

If you find that this package is an idea worth pursuing, please let me know. Developing is always more fun when it becomes a collaborative work. So please also email me (or leave an issue) if you want to get involved!



courtiol/packtrack documentation built on May 30, 2021, 12:10 a.m.