‘fusen’ v0.6.0 (beta): a new Rmd/Qmd parser with ‘lightparser’ to try before release
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.6.0 (beta): a new Rmd/Qmd parser with ‘lightparser’ to try before release
{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'))
- I suggest you to create a new git branch on your project to test this version of {fusen}.
- Try to inflate all your flat files:
fusen::inflate_all()
- Check the diff of your project to see if anything looks weird in the copy-pasting process.
- If you encounter any problem, please add a comment in this issue #237 on the {fusen} repo with a reproducible example: https://github.com/ThinkR-open/fusen/issues/237
Thanks !
fusen 0.6.0 with a new parser
{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:
- in the NEWS : https://thinkr-open.github.io/fusen/news/index.html
- or in the corresponding blog posts : https://rtask.thinkr.fr/fusen/
Note that there are other changes in this version of {fusen}:
- Allow organisation in
init_share_on_github()
to send to a GitHub organisation - Fix
load_flat_functions()
to work with VSCode
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:
- Inflate all your flat files at once with
fusen::inflate_all()
: https://rtask.thinkr.fr/fusen-v0-5-gotta-inflate-em-all/ and https://thinkr-open.github.io/fusen/articles/inflate-all-your-flat-files.html - Share your package with full documentation and CI/CD on GitHub in one command with
fusen::init_share_on_github()
: https://thinkr-open.github.io/fusen/articles/share-on-a-github-website.html - {fusen} works on VSCode
This post is better presented on its original ThinkR website here: ‘fusen’ v0.6.0 (beta): a new Rmd/Qmd parser with ‘lightparser’ to try before release
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.