• Stars
    star
    162
  • Rank 232,284 (Top 5 %)
  • Language
    R
  • License
    Other
  • Created over 4 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Inflate your package from a simple flat Rmd / Qmd

fusen

fusen status badge CRAN status R-CMD-check codecov

{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.

Fill the flat Rmd (or qmd) template with everything in one place and {fusen} will inflate the identified parts in the correct package files and directories.

The {fusen} Rmarkdown template encourages users to fill their documentation and tests at the same time of writing their functions code. Thanks to the R package structure used by {fusen}, you can built a robust workflow or R package. {fusen} simplifies and reduces the number of steps towards a full R package.
After that, your {pkgdown} documentation website is one command away to be shared with all your users.

This {fusen} package is a real-world example of {fusen} use as it was itself created from the flat templates available in "dev/" folder in its GitHub repository.

Installation

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:

# From r-universe.dev (No need for GITHUB_PAT)
options(repos = c(
  thinkropen = "https://thinkr-open.r-universe.dev",
  CRAN = "https://cloud.r-project.org"
))
# Download and install {fusen} in R
install.packages("fusen")

# With {remotes} using GitHub API - Need for GITHUB_PAT
# install.packages("remotes")
remotes::install_github("ThinkR-open/fusen")

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

You are one Rmd away from building a package!

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

  • Create a new directory / new project with
    • RStudio template: File > New Project > New directory > Package using {fusen}
  • Choose the template
    • Choose the template teaching the first time to see how {fusen} works,
    • Choose the template full the second time to answer most of your questions
    • Or command line: create_fusen("path/to/new/project", template = "teaching")
  • Open the “dev/flat_teaching.Rmd” to start setting up the package
  • In this flat Rmd template, run the first chunks named description asking to describe your package and license it
    • They look like these lines of code:
fill_description(fields = list(Title = "My Awesome Package"))
usethis::use_mit_license("John Doe")
  • Write your analysis and functionalities following the Rmd template
    • You probably develop them with a few examples and tests
    • For the first time, you can let the code as is, this is already the content for a working package
  • Run the following code to transform the flat Rmd as an inflated package
    • This will open the vignette created
fusen::inflate(
  flat_file = "dev/flat_teaching.Rmd",
  vignette_name = "Get started",
  check = TRUE
)
  • Share it on a website on GitHub
fusen::init_share_on_github()

That’s it! You built a package! A documented and tested package!
You even have a website for it!

Let’s test it now:

  • Install your package locally
remotes::install_local()
  • Restart your R session to clean environment
    • You can restart your RStudio session to let appear the “Build” tab panel
  • Test functions of your package
my.package::my_median(1:12)

Description of the Rmd template

As I said earlier, this is all about using the correct split and name for your chunks.

  • Follow the "dev/flat_template.Rmd" template to write your documentation and build your functions and test your examples.
    • Chunk named function gets the code of a function
    • Chunk named example gets the code for examples of using the function. This will be used for function @examples and will be kept for the vignette.
      • As chunk names should be unique in the future vignette, you can add function names like example-myfunction, example-myotherfunction, …
    • Chunk named tests gets the code for unit testing
    • Chunk named development gets the code for development purposes, usually only used once like {usethis} functions
  • Inflate the flat Rmd template to transform it as a package with functions, unit tests and the current Rmd transformed as a vignette. And check.

Note that the "flat*.Rmd" files created with templates full and teaching are indeed working examples that can directly be inflated.

You can also have a look at {squirrels.fusen} that has been built to present the method. Follow the commits: https://github.com/statnmap/squirrels.fusen/commits/main

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

There is a dedicated vignette to answer this: https://thinkr-open.github.io/fusen/articles/Maintain-packages-with-fusen.html

  • Option 1: Modifications are only added to the “flat_template.Rmd” file, which then is inflated to update all packages files
  • Option 2: Modifications are realized in the package files directly, and the “flat_template.Rmd” file must be protected from any use.

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

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. 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. Think also about code review: everything related to one function is at the same place.

Q&A : All tips and tricks of a {fusen} template

  • Can I be lazy in names used?
  • Can I knit the content of the flat template ?
  • How to declare packages with library() for the future vignette ?
  • How to include examples that cannot be run ?
  • Document your internal datasets in a function chunk as usual
  • How to ignore some chunks ?
  • How to create a vignette with different title and Index Entry?
  • How not to create a vignette ?
  • How to get a pre-filled template for a specific function name ?
  • How to Inflate multiple flat files ?
  • How to store multiple functions in a unique R file ?
  • How to read dataset that I usually put in “tests/testthat/” for my unit tests?
  • Can I load all functions of the current flat file during development without having to inflate()?
  • Can I inflate a Quarto qmd file?
  • Can I use {fusen} with {golem}?

=> See vignette Tips and Tricks: https://thinkr-open.github.io/fusen/articles/tips-and-tricks.html

Why is this package named {fusen} ?

A fusen is an origami. It is a flat 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 a flat Rmd template, that you fill in a specific way so that at the end, you can magically inflate() it to let a nice package appear.

Click here to fold your {fusen}…

Acknowledgments

Code of Conduct

Please note that the {fusen} project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

More Repositories

1

golem

A Framework for Building Robust Shiny Apps
R
902
star
2

remedy

RStudio Addins to Simplify Markdown Writing
R
448
star
3

companies-using-r

A Curated list of R uses in entreprise
247
star
4

prepare-for-cran

A Collaborative list of things to know before submitting to CRAN
232
star
5

engineering-shiny-book

Engineering Production-Grade Shiny Apps — Published in the R Series
TeX
217
star
6

dockerfiler

Easy Dockerfile Creation from R
R
176
star
7

fakir

Create Fake Data in R for tutorials
R
132
star
8

shinipsum

Lorem-Ipsum-like Helpers for fast Shiny Prototyping
R
115
star
9

attachment

Tools to deal with dependencies in scripts, Rmd and packages
R
104
star
10

shinysnippets

A series of shiny related RStudio Snippets
R
101
star
11

fcuk

A R package designed to help people with clumsy fingers.
R
89
star
12

wedding

Shiny app with custom css to prepare and manage a wedding
R
54
star
13

togglr

an R and Rstudio wrapper for toggl Api
R
46
star
14

gitlabr

An R client for the GitLab API
R
40
star
15

mariobox

A Framework For Packaging {plumber} APIs
R
37
star
16

devindocker

Development in a Docker container
R
37
star
17

seven31

R 📦 for R FAQ 7.31
R
36
star
18

checkhelper

A package to help deal with devtools::check outputs
R
34
star
19

gitdown

Document each modification of your software by turning your git commits into a gitbook
R
34
star
20

littleboxes

Rstudio Addin - create boxed title in an Rscript
R
33
star
21

licensing-r

A Bookdown about R & licenses
HTML
32
star
22

thinkr

Some tools for cleaning up messy 'Excel' files to be suitable for R
R
30
star
23

prompt

Dynamic prompt
R
28
star
24

testdown

Turn your 'testthat' results into a Bookdown.
R
26
star
25

prenoms

French Baby Names 1900-2020
R
23
star
26

ztype

How fast can you type R functions on your keyboard ?
R
23
star
27

tagsinput

Bootstrap tags input for shiny
R
20
star
28

tweetstorm

tweetstorm
R
19
star
29

utf8splain

Explain utf-8 encoded strings
R
18
star
30

js4shinyfieldnotes

Field Notes on JavaScript for Shiny Users
HTML
13
star
31

brighter

A toolbox of functions for easier shiny development.
R
12
star
32

rtodoist

Package to call the todoist API. Manage your ToDo lists with todoist from R.
R
12
star
33

who

Data from the World Health Organisation
R
12
star
34

papillon

Build And Highlight Package Documentation With Customized Templates
R
11
star
35

isc-proposal

RConsortium ISC Proposal — "Rebooting and Extending R for Neo4J"
9
star
36

bank

Alternative caching backends for `{memoise}` & `{shiny}`.
R
9
star
37

stopwords

stop words in several languages
R
9
star
38

prenomsapp

A Web App for French Baby Names
R
8
star
39

uni

unicode tibble
R
8
star
40

timer

A dead simple timer page written in JavaScript
TypeScript
8
star
41

shinidraw

R
7
star
42

arpr

Advanced R Pipes
R
7
star
43

datasets

Various datasets, free to use
R
6
star
44

elvis

'Shiny' renderers and observers made safer
R
6
star
45

spongecake

Transform a Movie into a Synthetic Picture.
R
6
star
46

golem-workshop

Repo for the Golem Workshop during ThinkR & RStudio Roadshow 2019
6
star
47

purrple

some html widgets
JavaScript
6
star
48

signature

🖊️ Fill in your email signature from a template
R
5
star
49

ghooks

'Golem' Hooks for Standard 'Shiny' Apps
R
5
star
50

rusk

Multiplication Tables On a Modular Circle
R
5
star
51

prague

Where golems come to life
R
5
star
52

isc-proposal-licence

Licensing R - Guidelines and tools
5
star
53

inca3

Jeux de données issu de l’étude de consommation alimentaire des français inca3 de l'ANSES
R
5
star
54

legislatives2017

Résultat des elections legislatives 2017
R
4
star
55

mongooser

A port of MongooseJS to R
R
4
star
56

lozen

The objective of {lozen} is to centralize project management tools for Devs and Lead Devs.
R
4
star
57

tutor

R
4
star
58

thinkrdashboard

State of ThinkR open-source projects
R
4
star
59

w3css

[WIP] Implementation of W3.CSS for {shiny}
R
4
star
60

shinytodocx

POC permettant de montrer comment construire un rapport .docx à partir d 'une application shiny
HTML
4
star
61

googlefonts

using google fonts in shiny applications
R
3
star
62

clientapp

Showcase of Shiny App for client database and after-sales calls exploration
R
3
star
63

installR

script d'installation de configuration de R
R
3
star
64

tremousser

📦 R package to build charts and dashboards in Shiny based on Tremor.so
CSS
3
star
65

rstudioconf2019

An e-poster given during the rstudio::conf(2019).
3
star
66

docker4dev

Repository with DockerFiles for tutorials
R
2
star
67

architekter

A tool to extract a {ggplot2} theme from a Figma file
R
2
star
68

golemverse.org

golemverse
JavaScript
2
star
69

golemstream

Streams by the {golem} team
HTML
2
star
70

fa

font awesome R tools
R
2
star
71

bookshiny

R
2
star
72

ipsum

dummy text generator
R
2
star
73

rfrance

Aggregation de blog sur #rstats en 🇫🇷
CSS
2
star
74

activecollabr

Access the active collab API from R.
R
2
star
75

gemstones

Make Your 'golem' App Shine
R
2
star
76

abcdR

1
star
77

thinkr-hex-stickers

HQ hex and visuals for ThinkR projects
1
star
78

thinkrtemplate

A pkgdown template for ThinkR packages
CSS
1
star
79

axonaut

axonaut API for R
R
1
star
80

cranology

R
1
star
81

tetraclasse

Satisfaction analysis - LLosa matrix - Tetraclasse model
R
1
star
82

emojitsu

Emoji Grammar
R
1
star
83

thinkr-open.r-universe.dev

Packages for the ThinkR Universe
1
star
84

example.auto

Repository for automatic repo management tests
R
1
star
85

quakr

🌈 Quakr formats for revealjs
SCSS
1
star
86

iframe.illustrations

Some iframe for our blog posts on thinkr.fr
HTML
1
star
87

slack

slack API for R
R
1
star
88

blogs-comments

Comments on our blog posts with Utterances
1
star
89

meetup-r

Meetup "R, vous avez dit R ?"
1
star