-
Notifications
You must be signed in to change notification settings - Fork 2
/
create_qmd.R
107 lines (91 loc) · 3.4 KB
/
create_qmd.R
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
## Generate reports based on config list
library(dplyr)
library(purrr)
library(hoaddata)
library(ymlthis)
library(readr)
library(fs)
# Load agreements
my_ta <- readr::read_csv("config.csv")
# Get ISSNs
get_ta_jns <- function(publisher = NULL, collection = c("jct", "oam")) {
match.arg(collection)
if (collection == "jct") {
issn_l <- hoaddata::jct_hybrid_jns |>
dplyr::filter(esac_publisher == publisher) |>
distinct(issn_l) |>
pull(issn_l)
} else {
issn_l <- hoaddata::oam_hybrid_jns |>
dplyr::filter(vertrag == publisher) |>
distinct(issn_l) |>
pull(issn_l)
}
tibble::tibble(issn_l = issn_l, publisher = publisher, collection = collection) |>
# Create directory paths
mutate(dir_name = paste0(
collection,
"/",
tolower(gsub(" |[()]", "", publisher))
))
}
ta_jns <- purrr::pmap_df(list(publisher = my_ta$publisher, collection = my_ta$collection), get_ta_jns)
# Create directories
ta_dir_create <- function(ta_dirs = NULL) {
lapply(ta_dirs, fs::dir_create)
}
# Copy funder logo
funding_cp <- function(ta_dirs = NULL) {
lapply(ta_dirs, function(x) {
fs::file_copy(c("funding_note.md", "dfg_logo.jpg", "sub_logo.svg"), x, overwrite = TRUE)
})
}
# Create templates
ta_template_create <- function(.publisher = NULL, ...) {
my_df <- ta_jns |>
dplyr::filter(publisher %in% .publisher)
# Title
if (unique(my_df$collection) == "jct") {
my_title <- paste0(
unique(my_df$publisher),
": Hybrid Journals in Transformative Agreements"
)
my_subtitle <- paste0("How open are ", unique(my_df$publisher), "'s hybrid journals included in transformative agreements, as listed by the [cOAlition S Journal Checker Tool](https://journalcheckertool.org/transformative-agreements/)? You can analyse progress made over time by open license, publisher and country. You can also monitor the availability of publisher-provided metadata in Crossref.")
} else {
my_title <- unique(my_df$publisher)
my_subtitle <- paste0("How open are hybrid journals included in the German consortial transformative agreement ", unique(my_df$publisher), "? You can analyse progress made over time by open license, publisher and country. You can also monitor the availability of publisher-provided metadata in Crossref.")
}
# Template
ymlthis::yml() |>
ymlthis::yml_title(my_title) |>
ymlthis::yml_subtitle(my_subtitle) |>
ymlthis::yml_params(
issn_l = my_df$issn_l,
publisher = unique(my_df$publisher),
collection = unique(my_df$collection),
download_path = unique(my_df$dir_name)) |>
ymlthis::yml_discard(c("author", "date")) |>
ymlthis::use_rmarkdown(
path = paste0(unique(my_df$dir_name), "/index.qmd"),
template = "_portfolio_template.qmd",
include_yaml = TRUE,
open_doc = FALSE,
overwrite = TRUE
)
}
# Worklfow
# Load agreements
my_ta <- readr::read_csv("config.csv")
# Get journals specific to TA collection
ta_jns <- purrr::pmap_df(list(publisher = my_ta$publisher, collection = my_ta$collection), get_ta_jns)
# Create directories
ta_dir_create(unique(ta_jns$dir_name))
# Copy funding note
funding_cp(unique(ta_jns$dir_name))
# Create templates
purrr::walk(my_ta$publisher, ta_template_create)
# Move JCT overview
fs::file_copy("_jct_overview.qmd", "index.qmd", overwrite = TRUE)
# OAM overview
fs::file_copy("_oam_overview.qmd", "oam/index.qmd", overwrite = TRUE)
funding_cp("oam/")