‘fusen’ v0.6.0 (beta): a new Rmd/Qmd parser with ‘lightparser’ to try before release

banner with sticker logo of fusen package
Author : Sébastien Rochette
Categories : fusen, development, package, thinkrverse
Tags : fusen, lightparser, package, rmd-first, thinkr-package
Date :

{fusen} now relies on {lightparser} to detect the different parts of a Rmd or a Qmd file before inflating your flat file as a R package. Before the release on CRAN, I need you to test the development version and tell me if there are any edge cases with your flat files.

TL;DR

Please try the pre-release version of {fusen} with {lightparser}, so that I can get the edge cases before the CRAN release.

  • Install {fusen} and {lightparser} from r-universe:
install.packages('lightparser', repos = c('https://thinkr-open.r-universe.dev', 'https://cloud.r-project.org'))
install.packages('fusen', repos = c('https://thinkr-open.r-universe.dev', 'https://cloud.r-project.org'))
fusen::inflate_all()

Thanks !

fusen 0.6.0 with a new parser

hex log of fusen package{fusen} now uses {lightparser} instead of {parsermd} to detect the different parts of a Rmd or a Qmd file before inflating your flat file as a R package.

Changing the parser was driven by installation problems encountered with {fusen} and {parsermd} on CentOS or on Windows.

Error : C++14 standard requested but CXX14 is not defined

You can try this new version of {fusen} on your current projects. I suggest you to create a new git branch on your project to test this version of {fusen}.

Install {fusen} and {lightparser} from r-universe:

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

Try to inflate your current flat file or all your flat files at once:

fusen::inflate_all()

There will be known differences in the outputs:

  • The DESCRIPTION will stored the new version of {fusen}
  • Vignettes are rewritten with chunk parameter as Quarto list (#| eval: false) inside the chunk, instead of the old {r, eval = FALSE} parameter in the chunk call, whatever the way you declared them in the flat file.
  • You will probably see differences on the number of empty lines in the vignettes due to the way the different sections are detected and restored by {lightparser}.

Please report any suspect behaviour as a comment in this issue #237 on the {fusen} repo with a reproducible example, before I release this version on CRAN.

In theory, this should only affect the copy-pasting process of your flat file in the resulting R, test and vignettes files.
Depending on the version of {fusen} you used to use, changes may be bigger.
Please have a look at the history of changes:

Note that there are other changes in this version of {fusen}:

lightparser 0.0.1, the new parser for Rmd/Qmd files

{lightparser} is a light version of what {parsermd} was doing, but is C++ free. It was designed to be used with {fusen} but can be used independently.

This will also allow me to maintain {lightparser} with regards to the needs of {fusen}.

Install {lightparser} from r-universe:

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

Split your Rmd or Qmd file into a tibble:

library(lightparser)
file <- system.file(
  "dev-template-parsing.Rmd",
  package = "lightparser"
)
tbl_rmd <- split_to_tbl(file)
tbl_rmd
#> # A tibble: 35 × 8
#>    type    label       params       text     code  heading heading_level section
#>    <chr>   <chr>       <list>       <named > <lis> <chr>           <dbl> <chr>  
#>  1 yaml    <NA>        <named list> <lgl>    <lgl> <NA>               NA <NA>   
#>  2 inline  <NA>        <lgl [1]>    <chr>    <lgl> <NA>               NA <NA>   
#>  3 block   development <named list> <lgl>    <chr> <NA>               NA <NA>   
#>  4 inline  <NA>        <lgl [1]>    <chr>    <lgl> <NA>               NA <NA>   
#>  5 heading <NA>        <lgl [1]>    <chr>    <lgl> Descri…             1 Descri…
#>  6 inline  <NA>        <lgl [1]>    <chr>    <lgl> <NA>               NA Descri…
#>  7 block   description <named list> <lgl>    <chr> <NA>               NA Descri…
#>  8 inline  <NA>        <lgl [1]>    <chr>    <lgl> <NA>               NA Descri…
#>  9 heading <NA>        <lgl [1]>    <chr>    <lgl> Read d…             1 Read d…
#> 10 inline  <NA>        <lgl [1]>    <chr>    <lgl> <NA>               NA Read d…
#> # ℹ 25 more rows

You can re-create the Rmd/Qmd file from the tibble returned by split_to_tbl().
Before combining the tibble as a new file, you can modify its content by removing or adding rows, replacing content, etc.

file <- system.file("dev-template-parsing.Rmd",
  package = "lightparser"
)
# split first
tbl_rmd <- split_to_tbl(file)
# apply your filters on any part you'd like to remove
tbl_rmd_filtered <- tbl_rmd[-5, ]
# combine then
combine_tbl_to_file(tbl_rmd_filtered, tempfile(fileext = ".Rmd"))

What’s next?

I will release this version of {fusen} on CRAN in a few days if no problem is reported.
I hope these changes will make the installation of {fusen} easier for everyone, in particular for Windows and CentOS users.

In case you missed it, the last versions of {fusen} have seen some improvements:


Comments


Also read