Maintain packages with {fusen}

library(fusen)

Daily use of {fusen}

Add a new set of chunks in the current Rmd

Use the Addin “Add {fusen} chunks”

Create a new flat Rmd template

To add a new family of functions, create a new flat Rmd template

add_flat_template(template = "add")

How to maintain a {fusen}? Can I use {fusen} with old-way packages ?

After you inflate() the “flat_template.Rmd”, your code appears twice in the package. In the “flat_template.Rmd” itself and in the correct place for it to be a package. Take it as a documentation for the other developers.
Maintaining such a package requires a choice:

Your first inflate() may not directly work as expected as with any R code that you write. In this case, you can continue to implement your functionality using Option 1.

Advice 1 : Use Option 1 until you find it too complicated to be used ! I assure you, you will find the moment when you say : ok this is not possible anymore…

Advice 2 : Use git as soon as possible, this will avoid losing your work if you made some modifications in the wrong place

Option 1: Continue with the “flat_template.Rmd”

=> {fusen} itself is built as is. Each modification is added to the dedicated dev_history file and then inflated

Option 2: Maintain like a classical package

=> This is the way I add new functionalities in packages that started in the old way, and in specific cases where inflating is now too complicated, like for function inflate() and all its unit tests in this very {fusen} package.

What about packages already built the old way ?

The “flat_template.Rmd” template only modifies files related to functions presented inside the template. This does not remove or modify previous functions, tests or vignettes, provided that names are different.

Let’s try to convince package developers with an example

#' My median
#'
#' @param x Vector of Numeric values
#' @inheritParams stats::median
#'
#' @return
#' Median of vector x
#' @export
#'
#' @examples
my_median <- function(x, na.rm = TRUE) {
  if (!is.numeric(x)) {stop("x should be numeric")}
  stats::median(x, na.rm = na.rm)
}
my_median(1:12)
test_that("my_median works properly and show error if needed", {
  expect_true(my_median(1:12) == 6.5)
  expect_error(my_median("text"))
})

That’s it!
You added a new function in your package, along with example, test and a new vignette: