Site icon R-bloggers

‘fusen’ v0.3: Better project templates, grouped functions and numerous other enhancements

[This article was first published on Rtask, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

You can read the original post in its original format on Rtask website by ThinkR here: ‘fusen’ v0.3: Better project templates, grouped functions and numerous other enhancements

{fusen} gets some maturity! v0.3 is a big rebranding for a more fluid experience, from beginners to advanced developers. Creating a fully documented and tested package has never been so easy and enjoyable. Experience “Rmd first” to the fullest.

At first, I imagined {fusen} to help beginners start building R packages. Following the ‘Rmd first’ method, I am convinced that building a package is accessible to anyone. With {fusen}, this is even more true.
However, I am surprised myself with the opportunity given by {fusen} to help me, I can say an advanced R user, to build properly documented and tested packages, with ease. This reduces my mental load for so many tasks during development. And my colleagues at ThinkR are even more convinced than me!
If you already are a R developer and plan to create a new package, or add a new functionnality to your existing package, try it out. You’ll tell me later if it allows you to build better documented and tested packages.

Install {fusen} from CRAN or r-universe

You can install the released CRAN version:

install.packages("fusen")

Full documentation for the CRAN version is here: https://thinkr-open.github.io/fusen/

You can install the development version of {fusen} from GitHub:

install.packages("fusen", 
                 repos = "https://thinkr-open.r-universe.dev")

Full documentation for the development version is here: https://thinkr-open.github.io/fusen/dev/

Meet the {fusen} project template

{fusen} is all about correctly separating and naming chunks.

fill_description(fields = list(Title = "My Awesome Package"))
usethis::use_mit_license("Sébastien Rochette")
fusen::inflate(
  flat_file = "dev/flat_teaching.Rmd",
  vignette_name = "Get started",
  check = TRUE
)

That’s it! You built a package! A documented and tested package!

Create a {fusen} package from command line

library(fusen)
## Create a new project
dummypackage <- tempfile(pattern = "dummy")
# Create the template
dev_files <- create_fusen(dummypackage, template = "full", open = FALSE)
# Get the flat Rmd file template
flat_file <- dev_files[grepl("flat_", dev_files)]
# Fill description
fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package"))
# Inflate the package
inflate(
  pkg = dummypackage, 
  flat_file = flat_file,
  vignette_name = "Get started", check = TRUE,
  open_vignette = FALSE)

Add new pre-filled flat templates for your function

add_flat_template() replaces add_dev_history() to add a new flat template in your “dev/” directory.

There is also a RStudio Addin named “Add {fusen} chunks” that will add the set of three chunks, pre-filled with your function name, in the current Rmd file.

## my_func
```{r function-my_func}
#' Title
#' 
#' Description
#' 
#' @return
#' 
#' @export
my_func <- function(){
}
```
```{r example-my_func}
my_func()
```
```{r tests-my_func}
test_that("my_func works", {
  expect_true(inherits(my_func, "function")) 
})
```

Note that templates are now named flat_*.Rmd as we inflate a flat piece of paper into a nice package. The dev_history.Rmd file still exists to store all cross-functional tools like the {usethis} and {devtools} functions.

Group functions under the same R file after inflate

{fusen} inflates a flat Rmd template into multiple “.R” files in the “R/” and “tests/” directories. Although the development is only meant to take place in the flat template, you may want a concise organisation of these directories.

Version 0.3 allows to group some functions under the same “R/” and “tests/” files after inflate.

Functions are grouped in same R file and test file:

Find out more in the new Tips & Tricks vignette

Tips and tricks

I gathered multiple tips and tricks in a new vignette:
https://thinkr-open.github.io/fusen/articles/tips-and-tricks.html

All other enhancements described in NEWS

Breaking changes

Major changes

Minor changes

This post is better presented on its original ThinkR website here: ‘fusen’ v0.3: Better project templates, grouped functions and numerous other enhancements

To leave a comment for the author, please follow the link and comment on their blog: Rtask.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.