README.md

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 version 0.0.0.9000 is loaded: the usage of your packages is being tracked (@^@)!

packtrack_view() ## no packages used yet
#>     package         last_loaded times_loaded
#> 1 @^@_start 2021-05-26 11:44:20            0

library(stringr) ## we load stringr

packtrack_view() ## stringr has been imported
#>     package         last_loaded times_loaded
#> 1 @^@_start 2021-05-26 11:44:20            0
#> 2   stringr 2021-05-26 11:44:21            1

str_c("foo", "bar") ## we use a function not using dependencies
#> [1] "foobar"

packtrack_view() ## no package has been used
#>     package         last_loaded times_loaded
#> 1 @^@_start 2021-05-26 11:44:20            0
#> 2   stringr 2021-05-26 11:44:21            1

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

packtrack_view() ## several packages have been used
#>     package         last_loaded times_loaded
#> 1 @^@_start 2021-05-26 11:44:20            0
#> 2    crayon 2021-05-26 11:44:21            1
#> 3      glue 2021-05-26 11:44:21            1
#> 4 grDevices 2021-05-26 11:44:21            4
#> 5   methods 2021-05-26 11:44:21            2
#> 6     stats 2021-05-26 11:44:21            1
#> 7   stringr 2021-05-26 11:44:21            1
#> 8     utils 2021-05-26 11:44:21            5

packtrack_view(previously_loaded = TRUE) ## also includes the packages loaded before tracking
#>      package         last_loaded times_loaded
#> 1  @^@_start 2021-05-26 11:44:20            0
#> 2       base                <NA>            1
#> 3  codetools                <NA>            1
#> 4   compiler                <NA>            1
#> 5     crayon 2021-05-26 11:44:21            1
#> 6   datasets                <NA>            1
#> 7     digest                <NA>            1
#> 8   evaluate                <NA>            1
#> 9       glue 2021-05-26 11:44:21            1
#> 10  graphics                <NA>            1
#> 11 grDevices 2021-05-26 11:44:21            4
#> 12   hashmap                <NA>            1
#> 13 htmltools                <NA>            1
#> 14     knitr                <NA>            1
#> 15  magrittr                <NA>            1
#> 16   methods 2021-05-26 11:44:21            2
#> 17 packtrack                <NA>            1
#> 18      Rcpp                <NA>            1
#> 19     rlang                <NA>            1
#> 20 rmarkdown                <NA>            1
#> 21     stats 2021-05-26 11:44:21            1
#> 22   stringi                <NA>            1
#> 23   stringr 2021-05-26 11:44:21            1
#> 24     tools                <NA>            1
#> 25     utils 2021-05-26 11:44:21            5
#> 26      xfun                <NA>            1
#> 27      yaml                <NA>            1

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
#> [1] 26

sum(all_pkg$times_loaded == 0) ## number of packages not used during this session
#> [1] 217

packtrack_stop() ## tracking stops

detach(package:stringr) ## detach stringr

packtrack_start() ## tracking starts anew

packtrack_view() ## no packages used yet
#>     package         last_loaded times_loaded
#> 1 @^@_start 2021-05-26 11:44:21            0

packtrack_pause() ## tracking pauses

library(stringr)

packtrack_resume() ## tracking resumes

packtrack_view() ## tidyr has not been tracked
#>     package         last_loaded times_loaded
#> 1 @^@_start 2021-05-26 11:44:21            0

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.