Skip to content

Commit 5d02384

Browse files
committed
vignette: Convince pkg devs!
1 parent 4d693d1 commit 5d02384

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

vignettes/Maintain-packages-with-fusen.Rmd

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Your first `inflate()` may not directly work as expected. In this case, you can
5757

5858

5959

60-
## What about packages already built the old way ?
60+
# What about packages already built the old way ?
6161

6262
The "dev_history.Rmd" template only modifies files related to functions presented inside the template.
6363
This does not remove or modify previous functions, tests or vignettes, provided that names are different.
@@ -67,6 +67,52 @@ This does not remove or modify previous functions, tests or vignettes, provided
6767
- If you want to add new functionnalities, correctly documented and tested, you can use {fusen}. This will not delete previous work.
6868
- Use the "Option 2" above to continue after the development of your functionnality
6969

70+
## Let's try to convince package developers with an example
71+
72+
- Install {fusen} : `install.packages("fusen")`
73+
- Open a project for **one of your already existing package**
74+
+ Commit your previous state if you are afraid of {fusen}
75+
+ If you are not sure enough to do it on an existing package, then follow the guide in ["How to use fusen"](https://thinkr-open.github.io/fusen/articles/How-to-use-fusen.html)
76+
- Run in the Console : `fusen::add_dev_history(name = "additional")`
77+
+ A Rmd file appears in "dev/dev_history.Rmd". Open it.
78+
- Add a new function in the `function` chunk. For instance:
79+
```{r, eval=FALSE}
80+
#' My median
81+
#'
82+
#' @param x Vector of Numeric values
83+
#' @inheritParams stats::median
84+
#'
85+
#' @return
86+
#' Median of vector x
87+
#' @export
88+
#'
89+
#' @examples
90+
my_median <- function(x, na.rm = TRUE) {
91+
if (!is.numeric(x)) {stop("x should be numeric")}
92+
stats::median(x, na.rm = na.rm)
93+
}
94+
```
95+
- Add a corresponding example in the `example` chunk. For instance:
96+
```{r, eval=FALSE}
97+
my_median(1:12)
98+
```
99+
- Add a corresponding unit test in the `test` chunk. For instance:
100+
```{r, eval=FALSE}
101+
test_that("my_median works properly and show error if needed", {
102+
expect_true(my_median(1:12) == 6.5)
103+
expect_error(my_median("text"))
104+
})
105+
```
106+
- Run command of the last chunk: `fusen::inflate(rmd = "dev/dev_history.Rmd")`
107+
+ This will run {attachment} behind the scene and may modify the list of dependencies in the DESCRIPTION file accordingly. Use `fusen::inflate(rmd = "dev/dev_history.Rmd", document = FALSE)` to avoid that.
108+
+ This will also run `devtools::check()`. Use `fusen::inflate(rmd = "dev/dev_history.Rmd", check = FALSE)` to avoid that.
109+
110+
**That's it!**
111+
You added a new function in your package, along with example, test and a new vignette:
112+
113+
- R/my_median.R
114+
- tests/testthat/test-my_median.R
115+
- vignettes/exploration.Rmd
70116

71117

72118

0 commit comments

Comments
 (0)