Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/moodymudskipper/now
Remove Exported Functions Depending On Lifecycle
https://github.com/moodymudskipper/now
Last synced: 16 days ago
JSON representation
Remove Exported Functions Depending On Lifecycle
- Host: GitHub
- URL: https://github.com/moodymudskipper/now
- Owner: moodymudskipper
- License: other
- Created: 2023-10-11T10:50:35.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-11T11:33:18.000Z (about 1 year ago)
- Last Synced: 2024-08-13T07:11:06.395Z (4 months ago)
- Language: R
- Size: 13.7 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - moodymudskipper/now - Remove Exported Functions Depending On Lifecycle (R)
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
options(tidyverse.quiet = TRUE)
```# now
Experimental!
Forget about lifecycles, live in the {now}.
`now::clean_up()` removes functions of given life cycles from the namespace's exports so they're not attached with `library()` and not available or suggested with `::`.
Why would we want that ?
* You might not want to use deprecated functions, to use best current practice
* You might not want to use experimental functions, because you need to write stable code
* You might not want to run into defunct functions, that exist only to fail
* You might want to explore a package without being distracted by outdated or unstable
features.In short:
* `clean_up(pkgs)` is `clean_up(pkgs, remove = getOption("now.lifecycles", c("superseded", "deprecated", "defunct")))`.
* Additional possible options are `"experimental"`, `"questioning"`, and `"reexports"`,
the latter is not a life cycle, but allows you to drop reexports so you're forced
to use the source package when programming.
* For instance use`clean_up(pkg, lifecycle = "defunct")` to cleanup only defunct functions, and not break anything.
* Use`clean_up_tidyverse()` to do the above on all tidyverse packages at once.
* `clean_attach()` and `clean_attach_tidyverse()` are wrappers that call library> **It's not meant to be used in production, because it will break some dependencies that rely on the
features you've removed**Obviously life cycles are important and there are reasons why they exist, they
just sometimes get in the way.It works by looking at the doc and the code of a function, but we might miss
some "life-cycled" functions if the doc doesn't clearly use life cycle tags and the code
doesn't call a {lifecycle} function directly.## Installation
Install with
``` r
remotes::install_github("moodymudskipper/now")
```## Example
```{r, error = TRUE}
library(tidyverse)
before <- sapply(tidyverse_packages(), \(pkg) length(getNamespaceExports(pkg)))
do
locationnow::clean_up_tidyverse()
after <- sapply(tidyverse_packages(), \(pkg) length(getNamespaceExports(pkg)))
do
location
dplyr::do# expect some failures! Many packages use superseded functions in particular
library(dm)
```To avoid the latter, either :
* call `library(dm)` before cleaning up (these dependencies would
be copied in dm's imports env so `dm::separate()` would work but `tidyr::separate()` wouldn't)
* call `clean_up_tidyverse(force_keep = c("separate", "transmute"))` above to keep the necessary dependencies around.
* call `clean_up("dm")` or `clean_attach("dm")` before `clean_up_tidyverse()` and
don't be bothered with {dm}'s re-exportsLet's take a look at how much we can expect to trim off
```{r, error = TRUE}
# removing only superseded/deprecated/defunct
left_join(enframe(before, value = "before"), enframe(after, value = "after"), by = "name") |>
filter(after != before) |>
mutate(keep_ratio = sprintf("%2.0f%%", 100*after/before)) |>
arrange(keep_ratio) |>
knitr::kable()# removing additionally all experimental and questioning features, along with reexports
now::clean_up_tidyverse(c("experimental", "superseded", "deprecated", "defunct", "questioning", "reexports"))
after <- sapply(tidyverse_packages(), \(pkg) length(getNamespaceExports(pkg)))
left_join(enframe(before, value = "before"), enframe(after, value = "after"), by = "name") |>
filter(after != before) |>
mutate(keep_ratio = sprintf("%2.0f%%", 100*after/before)) |>
arrange(keep_ratio) |>
knitr::kable()
```