Site icon R-bloggers

fusen v0.5: Gotta inflate ’em all !

[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.5: Gotta inflate ’em all !

No more amnesia for {fusen}! With v0.5, it now has “memory”, allowing you to inflate all your flat files simultaneously. The aim of this latest version of {fusen} is to provide an ever smoother package development experience, for both novice and experiences users.

{fusen} continues to make life easier for package creators. One of the main changes in this new version is the appearance of a configuration file to list the links between a “parent” flat file (in the dev/ directory) and its “child” files (in the R/, tests/ and vignettes/ directories). This file provides {fusen} with memory, and is the cornerstone of a major v0.5 feature: the ability to automatically run an inflate_all() on all your flat files at the same time!

For less experienced {fusen} users, please feel free to consult our previous articles, and for the more experienced, please read on.

Our previous articles :

Installation

{fusen} is available on CRAN and developed on GitHub. You can access the full documentation website on this page: https://thinkr-open.github.io/fusen/. It also appears on the page ThinkR r-universe if you want to install the development version without GitHub API constraints.

Install CRAN version

install.packages("fusen")

Install development version

install.packages('fusen', repos = c('https://thinkr-open.r-universe.dev', 'https://cloud.r-project.org'))

{fusen} lists all the files in your package

On packages developed with {fusen} >= v0.5, we note the appearance of a dev/config_fusen.yaml configuration file. This file introduces the notion of “memory” into {fusen}. The configuration file lists the links between a “parent” flat file and its “child” files. It is updated each time the inflate() function is called on a given flat file. The parameters used to configure the inflate() call are also stored here.

This will enable you to keep track of the link between flat files, and all files in the R/, tests/ and vignettes/ directories. The configuration file also lists all files not originating from a flat file, which may give you an opportunity to clean up your package if necessary.

I am developing a new package with {fusen} v0.5.1, what should I do?

Nothing special, apart from taking advantage of the new features straight away! The configuration file will appear after the first call to inflate() and will be updated with each new call.

I have started a package with a version of {fusen} prior to v0.5.1, what should I do?

The easiest way is to run a fusen::inflate_all_no_check() and follow the instructions returned by the function.

It is likely that you will have to:

  1. Run an inflate() of each of your flat files with this version of {fusen}.
  2. Run fusen::check_not_registered_files() to list files not listed in the configuration file.
  3. Check the contents of the dev/config_not_registered.csv file.
  4. Clean your package of the files listed in step 3, if necessary.
  5. Register all remaining unregistered files with fusen::register_all_to_config().

Retry a call to fusen::inflate_all_no_check() or fusen::inflate_all() and you should be able to continue your package development serenely.

I have started a package without {fusen}, what should I do?

To continue your package with {fusen}, you’ll need to implement your new functionalities in a first flat file. Once this is done, you can follow the procedure described in the previous section.

What does the configuration file look like?

The configuration file, found in dev/config_fusen.yaml, lists all flat files that have been inflated, the files created during this operation and the parameters used to call the inflate() function.
Other files, not originating from flat files, are also listed, under a section called “keep”.

Below is an example of a configuration file:

flat_file1.Rmd:
  path: dev/flat_file1.Rmd
  R:
  - R/function1.R
  - R/function2.R
  tests:
  - tests/testthat/test-function1.R
  - tests/testthat/test-function2.R
  vignettes: vignettes/How-to-use-these-2-awesome-functions.Rmd
  inflate:
    flat_file: dev/flat_file1.Rmd
    vignette_name: First vignette to read
    open_vignette: false
    check: false
    document: true
    overwrite: 'yes'  
flat_file2.Rmd:
  path: dev/flat_file2.Rmd
  R:
  - R/function3.R
  - R/function4.R
  tests:
  - tests/testthat/test-function3.R
  - tests/testthat/test-function4.R
  vignettes: vignettes/Yet-another-vignette-to-read.Rmd
  inflate:
    flat_file: dev/flat_file2.Rmd
    vignette_name: Yet another vignette to read
    open_vignette: false
    check: false
    document: true
    overwrite: 'yes'
keep:
  path: keep
  R:
  - R/my_R_file1_from_my_previous_work.R
  - R/my_R_file2_from_my_previous_work.R
  tests:
  - tests/testthat/test-my_previous_work.R
  vignettes: vignettes/my_vignette_from_my_previous_work.Rmd

This configuration file tells us that the package contains 2 flat files: flat_file1.Rmd and flat_file2.Rmd. These are associated with 2 files in the R/ directory, 2 files in the tests/ directory and 1 file in the vignettes/ directory, respectively. These 2 files have been inflated with the latest version of {fusen}, as the parameters used to call the inflate() function are also listed.
Finally, in the “keep” section, you’ll find files from previous developments made for this package, prior to the use of {fusen}.

For more information ?

Go to the dedicated vignette.

How do I inflate all my flat files at once?

Is your package starting to include a lot of flat files, and you’re getting tired of having to inflate each one by hand on a regular basis? With this version of {fusen} comes the inflate_all() function!

Each call to inflate() now stores the function’s call parameters in the aforementioned configuration file. The inflate_all() function will reuse these parameters to serially inflate all your files. This means that a flat file must be manually inflated with inflate() before it can be used via inflate_all().

I have started a package with a version of {fusen} prior to v0.5.0, what should I do?

The configuration file is absent from your project, so calling an inflate() on each of your flat files will create the configuration file and fill it in.

I already knew about the configuration file but I have started a package with a development version of {fusen} prior to v0.5.1, what should I do?

The configuration file exists in your project, and lists the links between the flat files and the files in R/, tests/ and vignettes/, but the section relating to inflate() parameters is empty! To fill it in, you’ll need to make a manual call to inflate() for each flat file.

For more information ?

Go to the dedicated vignette.

In the end, is it hard to upgrade to the new version of {fusen}?

Not at all!

With {fusen} v0.5.1, you now have:

{fusen} and {attachment}

The purpose of the {attachment} package is to help you manage dependencies during the development of your package. {attachment} is used by {fusen} when calling an inflate() to update package documentation and dependencies.

With {attachment} v0.4.0, a configuration file also appears, similar to the one used by {fusen}. For optimum cooperation between these two packages, we recommend that you also use this version of {attachment}.

To find out more about this latest version and the collaboration between {fusen} and {attachment}, please consult these resources:

NEWS content (v0.5.0 + v0.5.1)

New features

Inflate all active flat file

List all files created with an inflate() in a config file with parameters

Publish your package website on GitHub

List all files created with an inflate() in a config file

Others

Breaking changes

Major changes

Minor changes

Bug fixes

This post is better presented on its original ThinkR website here: fusen v0.5: Gotta inflate ’em all !

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.
Exit mobile version