Site icon R-bloggers

{fusen}: Create a package from a simple RMarkdown file

[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}: Create a package from a simple RMarkdown file

You know how to build a Rmd, you were said or would like to put your work in a R package, but you think this is too much work? You do not understand where to put what and when? What if writing a Rmd was the same as writing a package? Let {fusen} help you with this.

You are one RMarkdown away from building a package!

remotes::install_github("ThinkR-open/fusen")
dev_file <- fusen::add_dev_history(open = TRUE)
fill_description(fields = list(Title = "My Awesome Package"))
usethis::use_mit_license("Sébastien Rochette")
fusen::inflate(rmd = dev_file, name = "my-functionnality", check = TRUE)

That’s it! You built a package!

Who is {fusen} for?

When you write a RMarkdown file (or a vignette), you create a documentation for your analysis (or package). Inside, you write some functions, you test your functions with examples and you maybe write some unit tests to verify the outputs. This is even more true if you follow this guide : ‘Rmd first’: When development starts with documentation.
After that, you need to move your functions and scripts in the correct place. Well, let {fusen} do that for you!

{fusen} is first addressed to people who never wrote a package before but know how to write a RMarkdown file. Understanding package infrastructure and correctly settling it can be frightening. {fusen} helps you do the first steps.

{fusen} is also addressed to more advanced developers who are fed up with switching between R files, tests files, vignettes. In particular, when changing arguments of a function, we need to change examples, unit tests in multiple places. Here, you can do it in one place. No risk to forget one.

Why is this package named {fusen} ?

A fusen is an origami. It is a piece of paper that you fold in a specific way so that at the end, you can magically inflate it to let a nice box appear.

Similarly, the {fusen} package uses one page of RMarkdown, that you fill in a specific way so that at the end, you can magically inflate() it to let a nice package appear.

The RMarkdown template

Note that the "dev_history.Rmd" template is indeed a working example.
Note also that {fusen} is itself created from the "dev_history.Rmd" template available in its GitHub repository.

A reproducible example

# Create a new project
tmpdir <- tempdir()
dummypackage <- file.path(tmpdir, "dummypackage")
dir.create(dummypackage)
# {fusen} steps
# Add the template in your package
dev_file <- fusen::add_dev_history(pkg = dummypackage, overwrite = TRUE)
# Description
fusen::fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package"))
# Define License with use_*_license()
usethis::use_mit_license("Sébastien Rochette")
# You may need to execute inflate() in the console directly
fusen::inflate(pkg = dummypackage, rmd = dev_file, name = "exploration")
# Build {pkgdown} to test it
pkgdown::build_site(pkg = dummypackage)
# > See references and articles
# Hide output from package and git
usethis::use_build_ignore("docs")
usethis::use_git_ignore("docs")

Aknowledgments

< details> < summary>> Click here to fold your {fusen}…

This post is better presented on its original ThinkR website here: {fusen}: Create a package from a simple RMarkdown file

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.