---
title: "Split a Rmd or Qmd file into a tibble and vice-versa"
output: rmarkdown::html_vignette
author: "statnmap"
date: "2021-01-23"
vignette: >
  %\VignetteIndexEntry{z-split-a-rmd-or-qmd-file-into-a-tibble-and-vice-versa}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

```{r setup}
library(lightparser)
```

<!-- WARNING - This vignette is generated by {fusen} from dev/flat_split_combine.Rmd: do not edit by hand -->



# Parse and split a Rmd / Qmd file, and transform as tibble

{lightparser} reads your flat file to detect what is a yaml header, 
what is a code chunk and its options, what is a text part.  
Function `split_to_tbl()` returns a tibble with all these parts.

```{r examples}
file <- system.file(
  "dev-template-parsing.Rmd",
  package = "lightparser"
)
split_to_tbl(file)
```




<!--
# split_headers_from_text
---> 


<!-- 
# Test other formats
-->

# Combine a parsed tbl Rmd / Qmd file into a new file

You can re-create the Rmd/Qmd file from the tibble returned by `split_to_tbl()`.
As this is a tibble, before combining it as a new file, you can modify its content by removing or adding rows, replacing content, etc.
    
  
```{r example-combine_tbl_to_file}
file <- system.file("dev-template-parsing.Rmd",
  package = "lightparser"
)
# split first
tbl_rmd <- split_to_tbl(file)
# apply your filters
tbl_rmd_filtered <- tbl_rmd[-5, ]
# combine then
combine_tbl_to_file(tbl_rmd_filtered, tempfile(fileext = ".Rmd"))
```

  
  

<!--
# Combine other formats
-->
