generated from just-the-docs/just-the-docs-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrmd_to_md.Rmd
More file actions
86 lines (67 loc) · 1.74 KB
/
rmd_to_md.Rmd
File metadata and controls
86 lines (67 loc) · 1.74 KB
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
77
78
79
80
81
82
83
84
85
86
---
title: "R Markdown to Markdown conversion"
author: "Sanne Govaert"
date: "`r Sys.Date()`"
output: html_document
---
## Setup
### Select package
For what package do you want to (re)generate the documentation? See `vignettes.yml` for settings:
```{r}
package <- "gcube"
overwrite_b3verse <- FALSE
```
### Load libraries
```{r}
library(yaml)
library(purrr)
library(here)
```
### Install all b3verse packages
```{r}
if (overwrite_b3verse) {
pkgs <- rownames(available.packages(repos = "https://b-cubed-eu.r-universe.dev"))
install.packages(pkgs, repos = c("https://b-cubed-eu.r-universe.dev", "https://cloud.r-project.org", "https://bioc.r-universe.dev"))
}
```
### Read yaml
```{r}
yaml <- yaml::read_yaml(here::here("src", "rmd_to_md", "vignettes.yml"))
```
## Create documentation
### Select yaml
```{r}
yaml_package <- yaml[[package]]
```
### Install the packages used in the Rmd files
```{r}
dependencies <- unlist(
purrr::map(yaml_package, function(item) {
if (!is.null(item$dependencies)) {
unlist(strsplit(item$dependencies, "[ ,]+"))
} else {
NULL
}
})
)
purrr::map(unique(dependencies), ~ rlang::check_installed(.x))
```
### Convert vignettes
```{r}
md_dir <- here::here("src", "content", "docs", "software", package)
fig_dir <- here::here("public", "software", package)
fig_url_dir <- paste0("/software/", package, "/")
purrr::walk(
yaml_package,
~ b3doc::rmd_to_md(
.x$source,
md_dir,
fig_dir,
fig_url_dir,
title = purrr::pluck(.x, "title", .default = NULL),
sidebar_label = purrr::pluck(.x, "sidebar_label", .default = NULL),
sidebar_order = which(purrr::map_chr(yaml_package, "source") == .x$source),
replace = unlist(purrr::pluck(.x, "replace", .default = NULL))
)
)
```