Skip to content

Commit 5836908

Browse files
authored
Render for correct output in weigh() (#281)
* Render for correct output in `weigh()` * Make sure we don't run into this again in the future
1 parent 6dff2cc commit 5836908

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

README.Rmd

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ knitr::opts_chunk$set(
1111
fig.path = "man/figures/README-",
1212
out.width = "100%"
1313
)
14+
15+
# `devtools::build_readme()` evaluates in `callr:r_safe()` which causes issues
16+
# with butcher's memory profiling. Neither RStudio's Knit button nor
17+
# `rmarkdown::render()` have this issue (#280).
18+
if (identical(Sys.getenv("CALLR_IS_RUNNING"), "true")) {
19+
rlang::abort(c(
20+
"Build this README with `rmarkdown::render()` rather than `devtools::build_readme()`.",
21+
"See tidymodels/butcher#280 for more info."
22+
))
23+
}
1424
```
1525

1626
# butcher <a href="https://butcher.tidymodels.org"><img src="man/figures/logo.png" align="right" height="138" alt="butcher website" /></a>
@@ -29,7 +39,7 @@ Modeling or machine learning in R can result in fitted model objects that take u
2939
1. Heavy usage of formulas and closures that capture the enclosing environment in model training
3040
2. Lack of selectivity in the construction of the model object itself
3141

32-
As a result, fitted model objects contain components that are often redundant and not required for post-fit estimation activities. The butcher package provides tooling to "axe" parts of the fitted output that are no longer needed, without sacrificing prediction functionality from the original model object.
42+
As a result, fitted model objects contain components that are often redundant and not required for post-fit estimation activities. The butcher package provides tooling to "axe" parts of the fitted output that are no longer needed, without sacrificing prediction functionality from the original model object.
3343

3444
## Installation
3545

@@ -46,33 +56,33 @@ Or install the development version from [GitHub](https://github.com/):
4656
pak::pak("tidymodels/butcher")
4757
```
4858

49-
## Butchering
59+
## Butchering
5060

51-
As an example, let's wrap an `lm` model so it contains a lot of unnecessary stuff:
61+
As an example, let's wrap an `lm` model so it contains a lot of unnecessary stuff:
5262

5363
```{r example}
5464
library(butcher)
5565
our_model <- function() {
5666
some_junk_in_the_environment <- runif(1e6) # we didn't know about
57-
lm(mpg ~ ., data = mtcars)
67+
lm(mpg ~ ., data = mtcars)
5868
}
5969
```
6070

61-
This object is unnecessarily large:
71+
This object is unnecessarily large:
6272

6373
```{r}
6474
library(lobstr)
6575
obj_size(our_model())
6676
```
6777

68-
When, in fact, it should only be:
78+
When, in fact, it should only be:
6979

7080
```{r}
71-
small_lm <- lm(mpg ~ ., data = mtcars)
81+
small_lm <- lm(mpg ~ ., data = mtcars)
7282
obj_size(small_lm)
7383
```
7484

75-
To understand which part of our original model object is taking up the most memory, we leverage the `weigh()` function:
85+
To understand which part of our original model object is taking up the most memory, we leverage the `weigh()` function:
7686

7787
```{r}
7888
big_lm <- our_model()
@@ -113,8 +123,8 @@ Check out the `vignette("available-axe-methods")` to see butcher's current cover
113123

114124
1. Run `new_model_butcher(model_class = "your_object", package_name = "your_package")`
115125
2. Use butcher helper functions `weigh()` and `locate()` to decide what to axe
116-
3. Finalize edits to `R/your_object.R` and `tests/testthat/test-your_object.R`
117-
4. Make a pull request!
126+
3. Finalize edits to `R/your_object.R` and `tests/testthat/test-your_object.R`
127+
4. Make a pull request!
118128

119129
## Contributing
120130

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ weigh(big_lm)
8282
#> # A tibble: 25 × 2
8383
#> object size
8484
#> <chr> <dbl>
85-
#> 1 terms 8.05
85+
#> 1 terms 8.01
8686
#> 2 qr.qr 0.00666
8787
#> 3 residuals 0.00286
8888
#> 4 fitted.values 0.00286
@@ -102,7 +102,7 @@ remove the (mostly) extraneous component, we can use `butcher()`:
102102

103103
``` r
104104
cleaned_lm <- butcher(big_lm, verbose = TRUE)
105-
#> ✔ Memory released: 8.03 MB
105+
#> ✔ Memory released: 8.00 MB
106106
#> ✖ Disabled: `print()`, `summary()`, and `fitted()`
107107
```
108108

@@ -133,7 +133,7 @@ weigh(small_lm)
133133
#> # A tibble: 25 × 2
134134
#> object size
135135
#> <chr> <dbl>
136-
#> 1 terms 8.06
136+
#> 1 terms 0.00763
137137
#> 2 qr.qr 0.00666
138138
#> 3 residuals 0.00286
139139
#> 4 fitted.values 0.00286

0 commit comments

Comments
 (0)