{fusen} inflates a Rmarkdown file to magically create a package.
If you know how to create a Rmarkdown file, then you know how to build a package.
You can install the development version of {fusen} from GitHub:
# install.packages("remotes")
remotes::install_github("ThinkR-open/fusen")
Note that this package relies on {parsermd}, which is also under development and not currently released on CRAN.
{fusen} is all about correctly separating and naming chunks.
my.package
for instance
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!
Let’s test it now:
remotes::install_local()
my.package::my_median(1:12)
# Build {pkgdown} to test it
pkgdown::build_site()
# > See references and articles
# Hide output from package and git
usethis::use_build_ignore("docs")
usethis::use_git_ignore("docs")
As I said earlier, this is all about using the correct split and name for your chunks.
"dev/dev_history.Rmd"
template to write your documentation and build your functions and test your examples.
function
gets the code of a functionexample
gets the code for examples of using the function. This will be used for function @examples
and will be kept for the vignette.
example-1
, example-2
, …tests
gets the code for unit testingdevelopment
gets the code for development purposes, usually only used once like {usethis} functionsNote that the "dev_history.Rmd"
template is indeed a working example.
Note also that {fusen} was itself created from the "dev_history.Rmd"
template available in its GitHub repository.
# 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")
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. 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. This package may help them do the first step!
{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.
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.
Please note that the dummypackage project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.