forked from InseeFrLab/utilitR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.Rprofile
118 lines (91 loc) · 3.12 KB
/
.Rprofile
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
108
109
110
111
112
113
114
115
116
117
118
if (file.exists('~/.Rprofile')) sys.source('~/.Rprofile', envir = environment())
with_def <- (function() {
glossary <- yaml::read_yaml("resources/glossary.yml")
glossary <- as.data.frame(do.call(rbind, glossary), stringsAsFactors = FALSE)
function(term, def) {
if (missing(def)) {
def <- unlist(glossary[glossary$name == tolower(term), "desc"])
# quick and dirty pour aussi matcher les pluriels
if (length(def) == 0) def <- unlist(glossary[paste0(glossary$name, "s") == tolower(term), "desc"])
# quick and dirty pour aussi matcher les infinitif
if (length(def) == 0) def <- unlist(glossary[paste0(glossary$name, "r") == tolower(term), "desc"])
}
sprintf('<abbr title="%s"><b>%s</b></abbr>', def, term)
}
})()
render_rmd <- function(x) return(cat(htmltools::includeText(x)))
screen_files <- function(){
masterfile <- paste(readLines("_bookdown.yml"),
collapse = " ")
masterfile <- gsub(
'(\\[|\\]|\\")', "",
regmatches(masterfile,
gregexpr("\\[.+?\\]",
masterfile))[[1]]
)
masterfile <- unlist(
strsplit(
x = masterfile,
split = ","
)
)
masterfile <- trimws(masterfile)
masterfile <- masterfile[endsWith(masterfile, suffix = ".Rmd")]
return(masterfile)
}
get_hash <- function(){
list_files <- screen_files()
system2 <- function(...) {
stopifnot(!any(names(list(...)) %in% "intern"))
result <- base::system(..., intern = TRUE)
print(result)
}
return(
sapply(
list_files, function(k)
system2(paste0("git log -n 1 --pretty=format:%h ","./", k))
)
)
}
add_space <- function(){
files <- screen_files()
lapply(files, function(f) writeLines(c(readLines(f)," "),
con = f)
)
}
# Créer un dossier pour les images compressées (s'il n'existe pas déjà)
# Copier les images si elles ne sont pas déja dans le dossier
dossier_images <- './pics' # This folder must exist in the repo
dossier_images_compressees <- './pics_resized'
if (!dir.exists(dossier_images_compressees)) {
dir.create(dossier_images_compressees)
}
invisible(
file.copy(list.files(dossier_images, full.names = TRUE), dossier_images_compressees, recursive=TRUE, overwrite = TRUE)
)
reminder_image <- function(path = "moncheminperso"){
cat(
sprintf(
paste(
"```{r, echo = FALSE}",
"include_image(\"%s\")",
"```",
sep = "\n"
), path)
)
}
message(
cat(
c("Projet source de la documentation utilitR",
"-----------------------------------------",
"",
"Pour pr\u00E9visualiser la version web de l'ouvrage: ",
" * Option 1: utiliser l'onglet 'Build' dans Rstudio;",
" * Option 2: taper dans la commande R:
bookdown::render_book(\"index.Rmd\", output_dir = \"_public\", output_format = \"utilitr::bs4_utilitr\")",
"",
"Ne pas oublier d'installer le package 'utilitr' avant pour disposer des mod\u00E8les de documents:
remotes::install_github(\"https://github.com/InseeFrLab/utilitr-template\")"),
sep = "\n"
)
)