-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
106 lines (66 loc) · 4.12 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
set.seed(123)
```
# packtrack
<!-- badges: start -->
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
[![CRAN status](https://www.r-pkg.org/badges/version/packtrack)](https://CRAN.R-project.org/package=packtrack)
<!-- badges: end -->
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}__):
``` r
remotes::install_github("nathan-russell/hashmap") ## dependency needed
remotes::install_github("courtiol/packtrack")
```
## Example
```{r}
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
- better tracking (not all namespaces are being tracked in all circumstances)
- information collected will not disappear when you close R (by means of the package __{later}__ and/or __{callr}__ or __{processx}__)
- companion functions to explore the collected data and help you diagnose which R packages can be safely deleted from your system
## 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!