Skip to main content

{fusen}: Simplifying Writing Packages for R Users

By May 23, 2023Blog

The R Consortium recently talked to Sébastien Rochette, organizer of the Meetup R Nantes, about his involvement in the R community. The group hosts a mix of physical and online events targeting the full range of R users, from beginners to experts. Sebastien works for ThinkR and has recently developed a package named {fusen}. {fusen} allows developers to use a single Notebook file for writing the package documentation, code, and tests in the same place. 

Sébastien Rochette, Head of Production at ThinkR and Organizer of Meetup R Nantes

Please share your background and your involvement in the RUGS group or in the R Community.

I began using R for research and spatial data modelization 15 years ago. I started in high school and continued while I was a fisheries science researcher. Now I continue to use R every day as the Head of Production at ThinkR, where we work as consultants and teachers of R. Our work entirely revolves around R, from installing infrastructures to teaching to and certifying public and private users, or building packages and shiny applications for them. We are also certified full-service partners of Posit (RStudio)

I am also deeply invested in the open source and R community. At ThinkR, we develop many open-source R packages for our internal use, which we are happy to share with the community. We believe that building a business over an open-source project like R requires giving back to the community. I am also the organizer of Meetup R Nantes, which alternates between physical and online events. Physical events are great for networking, while online events ensure inclusivity for those unable to attend in person.

At all of our meetups, we have two presentations. One is aimed at beginners and the other is aimed at more experienced users or presenting a personal experience. This is to make sure that members of all experience levels feel included and can learn from the events.

Please share about a project you are currently working on or have worked on in the past using the R language. Goal/reason, result, anything interesting, especially related to the industry you work in?

I am currently working on a project called {fusen}, an open-source package designed to make package building easier. While developing packages, developers usually prioritize writing code and overlook documentation. This can cause problems when reusing or sharing code with colleagues or the community.

With {fusen}, we start by opening a template notebook file (RMarkdown or Quarto). This encourages writing about the code’s purpose in plain text as it is readable. Then, the user writes the code and an example within the R Markdown file. The script example can also be used to write a unit test. The RMarkdown template proposed by {fusen} encourages people to document everything they have in mind regarding their project. This reduces the risk of forgetting their goal the next time they code, but also sets the perfect basis for sharing their work: documentation and examples are there already. The {fusen} notebook template has different script parts for code, function, and test. {fusen} then inflates the file into a full package, with the documentation and examples in the vignette, the functions in the R directory, and the unit tests in the tests directory. This approach eliminates worries about the package structure and allows developers to write everything in a single RMarkdown file.

Figure 1. The classical code of a project is written in one or multiple notebook files, called flat files, which {fusen} inflates as a full R package. A complementary file called “dev_history.Rmd” contains steps for package level documentation, and a list of tools for collaborating and sharing the project. See {fusen} documentation for more information.

We had two goals in mind when developing {fusen}. The first is that developers no longer need to open multiple files to write their packages and can focus on their package’s purpose. The second is that it encourages developers to document and test their work while making it easier for new developers to write R packages.

What resources/techniques do/did you use? (Posit (RStudio), Github, Tidyverse, etc.)

As RStudio-certified resellers, we prefer working with Posit (previously RStudio). It is much easier for beginners to use, which makes it an excellent tool for teaching R. The {fusen} project is available on GitHub since it is an open-source package, making it easily accessible to the community.

Within the {fusen} package, I use base R code, as I have been writing R code long ago before Tidyverse arrived. However, from the Tidyverse, I use the ‘tibble’ format to benefit from its consistency in data frame structures. {fusen} also relies on a package called {parsermd}, which reads and parses R Markdown files as ‘tibbles’.

Our package {attachment} also has an important role in {fusen} in reducing the difficulty of writing R packages. It helps declare all package dependencies. {attachment} reads the ‘importForm’ declared and all different ways of calling a package in your code and fills the ‘Description’ file in the correct place as imports or suggests, depending on where the dependency was declared in the package. This ensures beginners do not need to worry about dependencies or open the ‘Description’ file to write it by hand.

Because sharing and collaborating is central in the philosophy of {fusen}, I also encourage developers to use ‘git’ platforms like GitLab or GitHub, and use packages like {pkgdown}, {covr} and {testthat} to share documentation and the quality of their work.

Is this an ongoing project? Please share any details or CTA for who should get involved!

Yes, it is indeed an ongoing project that we use every day in our work to build packages for our customers. Although I initially created {fusen} to assist beginners in writing packages, we have discovered that it is equally valuable for experts, as it allows you to write the entire package in a single file (or groups of files when needed). This also makes it much easier to reuse and re-factor your code: if you split your package, you only have one file to worry about.

We are constantly improving {fusen}, and my colleague Yohann is currently working on adding a new feature allowing us to ‘inflate’ multiple flat files at the same time. With big projects, like {golem} applications, developers are used to separate family of functions in different flat files. This coming functionality will allow you to inflate all at once. 

My call to action for the community is to give this package a try. Regardless of your level of expertise in R programming, {fusen} can make package writing much more accessible to you. We have been using it for testing purposes, but over time, we have realized that it is also quite convenient for experts. For instance, you can try {fusen} to add new functionalities to your already existing package, and it will work smoothly. You won’t have to change anything in the existing structure.

I would also like to encourage beginners to try {fusen}, as they are often hesitant to write packages. Writing a package can add complexity to your code due to CRAN-specific checks and other requirements, even if you do not want to send it on CRAN. However, {fusen} can simplify this process for you. We also have another package that is not on CRAN called {checkhelper}, which will help you identify some sources of package building problems. And, if finally, you decide to share your work on CRAN, you can follow our ‘Prepare for CRAN’ guide that we regularly update.

Note that {fusen} has a teaching flat template included, which shows a full example of a working package that you can use to explore its possibilities. You will see that you can build your package locally and have its documentation shared as a web page on GitHub in one command.

How do I Join?

R Consortium’s R User Group and Small Conference Support Program (RUGS) provides grants to help R groups around the world organize, share information and support each other. We have given grants over the past four years, encompassing over 65,000 members in 35 countries. We would like to include you! Cash grants and accounts are awarded based on the intended use of the funds and the amount of money available to distribute. We are now accepting applications!