-
Notifications
You must be signed in to change notification settings - Fork 3
/
z-split-a-rmd-or-qmd-file-into-a-tibble-and-vice-versa.Rmd
76 lines (54 loc) · 1.57 KB
/
z-split-a-rmd-or-qmd-file-into-a-tibble-and-vice-versa.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
---
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
-->