Skip to content

Commit 2a8809f

Browse files
Simplification des hooks pour gagner en flexibilité et clarté (#166)
* test nouveau hook * add hook in env * aussi partie visualisation * output chunk * clean * source Rprofile * add arg * Automated changes * Apply suggestions from code review * Automated changes * corrige typo * Automated changes * back to black * Automated changes * cacher 'exception * temp mod * Automated changes * retire la douille * Automated changes * gpd envoie plein de warnings * build light * artifacts trop lourds * Automated changes * back to normalcy [skip ci] * update Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent d1878f3 commit 2a8809f

31 files changed

+137
-457
lines changed

.Rprofile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,23 @@ reminder_box <- function(boxtype = "warning", type = c("html","markdown")){
186186
cat(box, sep = "\n")
187187
}
188188

189+
# Hook from Maelle Salmon: https://ropensci.org/technotes/2020/04/23/rmd-learnings/
190+
modif_plot <- function(x, options, dir_path) {
191+
hugoopts <- options$hugoopts
192+
paste0(
193+
"{", "{<figure src=", # the original code is simpler
194+
# but here I need to escape the shortcode!
195+
'"', paste0(dir_path,"/",x), '" ',
196+
if (!is.null(hugoopts)) {
197+
glue::glue_collapse(
198+
glue::glue('{names(hugoopts)}="{hugoopts}"'),
199+
sep = " "
200+
)
201+
},
202+
">}}\n"
203+
)
204+
}
205+
189206

190207
message("For local preview when the pages are built: blogdown::hugo_build(local = TRUE)")
191208

.github/workflows/netlify-test.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ jobs:
6868
npm install --unsafe-perm=true netlify-cli -g
6969
netlify init
7070
netlify deploy --alias=${BRANCHE_REF} --dir="public" --message "Preview deploy from ${BRANCHE_REF}"
71-
- uses: actions/upload-artifact@v1
72-
with:
73-
name: content
74-
path: content/
71+
# - uses: actions/upload-artifact@v1
72+
# with:
73+
# name: content
74+
# path: content/
7575
- name: Convert in ipynb with Jupytext
7676
run: |
7777
pip install jupytext

build/build.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
library(knitr)
2+
library(reticulate)
3+
14
content_rmd <- list.files("./content/course", recursive = TRUE, pattern = "*.Rmd", full.names = TRUE)
25

36
file.remove(
@@ -6,6 +9,10 @@ file.remove(
69
)
710
)
811

12+
knitr::knit_engines$set(python = reticulate::eng_python)
13+
knitr::opts_chunk$set(fig.path = "")
14+
knitr::opts_chunk$set(eval = TRUE, warning = FALSE, message = FALSE)
15+
916
lapply(
1017
content_rmd, function(i){
1118
print(sprintf("Rendering %s", i))

build/build_light.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
source(".Rprofile")
2+
3+
library(knitr)
4+
library(reticulate)
5+
16
content_rmd <- readLines("diff.txt")
27
content_rmd <- content_rmd[startsWith(content_rmd, "content/course")]
38
content_rmd <- content_rmd[endsWith(content_rmd, ".Rmd")]
@@ -10,6 +15,11 @@ file.remove(
1015
)
1116
)
1217

18+
knitr::knit_engines$set(python = reticulate::eng_python)
19+
knitr::opts_chunk$set(fig.path = "")
20+
knitr::opts_chunk$set(eval = TRUE, warning = FALSE, message = FALSE)
21+
22+
1323
lapply(
1424
content_rmd, function(i){
1525
print(sprintf("Rendering %s", i))

content/course/NLP/01_intro.Rmd

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,9 @@ summary: |
3232
```{r setup, include=FALSE}
3333
dir_path <- gsub(here::here(), "..", here::here("course","NLP"))
3434
35-
library(knitr)
36-
library(reticulate)
37-
knitr::knit_engines$set(python = reticulate::eng_python)
38-
knitr::opts_chunk$set(fig.path = "")
39-
knitr::opts_chunk$set(eval = TRUE, echo = TRUE, warning = FALSE, message = FALSE)
40-
41-
# Hook from Maelle Salmon: https://ropensci.org/technotes/2020/04/23/rmd-learnings/
4235
knitr::knit_hooks$set(
43-
plot = function(x, options) {
44-
hugoopts <- options$hugoopts
45-
paste0(
46-
"{", "{<figure src=", # the original code is simpler
47-
# but here I need to escape the shortcode!
48-
'"', paste0(dir_path,"/",x), '" ',
49-
if (!is.null(hugoopts)) {
50-
glue::glue_collapse(
51-
glue::glue('{names(hugoopts)}="{hugoopts}"'),
52-
sep = " "
53-
)
54-
},
55-
">}}\n"
56-
)
57-
}
36+
plot = function(x, options) modif_plot(x, options, dir_path = dir_path)
5837
)
59-
6038
```
6139

6240
```{r, echo = FALSE, results = 'asis', include = TRUE, eval = TRUE}

content/course/NLP/02_exoclean.Rmd

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,10 @@ summary: |
3131

3232
```{r setup, include=FALSE}
3333
dir_path <- gsub(here::here(), "..", here::here("course","NLP"))
34-
35-
library(knitr)
36-
library(reticulate)
37-
knitr::knit_engines$set(python = reticulate::eng_python)
38-
knitr::opts_chunk$set(fig.path = "")
39-
knitr::opts_chunk$set(eval = TRUE, echo = FALSE, warning = FALSE, message = FALSE)
40-
41-
# Hook from Maelle Salmon: https://ropensci.org/technotes/2020/04/23/rmd-learnings/
34+
knitr::opts_chunk$set(echo = FALSE)
4235
knitr::knit_hooks$set(
43-
plot = function(x, options) {
44-
hugoopts <- options$hugoopts
45-
paste0(
46-
"{", "{<figure src=", # the original code is simpler
47-
# but here I need to escape the shortcode!
48-
'"', paste0(dir_path,"/",x), '" ',
49-
if (!is.null(hugoopts)) {
50-
glue::glue_collapse(
51-
glue::glue('{names(hugoopts)}="{hugoopts}"'),
52-
sep = " "
53-
)
54-
},
55-
">}}\n"
56-
)
57-
}
36+
plot = function(x, options) modif_plot(x, options, dir_path = dir_path)
5837
)
59-
6038
```
6139

6240
```{r, echo = FALSE, results = 'asis', include = TRUE, eval = TRUE}

content/course/NLP/03_lda.Rmd

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,10 @@ summary: |
3232

3333
```{r setup, include=FALSE}
3434
dir_path <- gsub(here::here(), "..", here::here("course","NLP"))
35-
36-
library(knitr)
37-
library(reticulate)
38-
knitr::knit_engines$set(python = reticulate::eng_python)
39-
knitr::opts_chunk$set(fig.path = "")
40-
knitr::opts_chunk$set(eval = TRUE, echo = FALSE, warning = FALSE, message = FALSE)
41-
42-
# Hook from Maelle Salmon: https://ropensci.org/technotes/2020/04/23/rmd-learnings/
4335
knitr::knit_hooks$set(
44-
plot = function(x, options) {
45-
hugoopts <- options$hugoopts
46-
paste0(
47-
"{", "{<figure src=", # the original code is simpler
48-
# but here I need to escape the shortcode!
49-
'"', paste0(dir_path,"/",x), '" ',
50-
if (!is.null(hugoopts)) {
51-
glue::glue_collapse(
52-
glue::glue('{names(hugoopts)}="{hugoopts}"'),
53-
sep = " "
54-
)
55-
},
56-
">}}\n"
57-
)
58-
}
36+
plot = function(x, options) modif_plot(x, options, dir_path = dir_path)
5937
)
60-
38+
knitr::opts_chunk$set(echo = FALSE)
6139
```
6240

6341
```{r, echo = FALSE, results = 'asis', include = TRUE, eval = TRUE}

content/course/NLP/04_word2vec.Rmd

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,11 @@ summary: |
3434
---
3535

3636
```{r setup, include=FALSE}
37-
library(knitr)
38-
library(reticulate)
39-
knitr::knit_engines$set(python = reticulate::eng_python)
40-
knitr::opts_chunk$set(fig.path = "")
41-
knitr::opts_chunk$set(eval = TRUE, echo = FALSE, warning = FALSE, message = FALSE)
42-
43-
# Hook from Maelle Salmon: https://ropensci.org/technotes/2020/04/23/rmd-learnings/
37+
dir_path <- gsub(here::here(), "..", here::here("course","NLP"))
4438
knitr::knit_hooks$set(
45-
plot = function(x, options) {
46-
hugoopts <- options$hugoopts
47-
paste0(
48-
"{", "{<figure src=", # the original code is simpler
49-
# but here I need to escape the shortcode!
50-
'"', x, '" ',
51-
if (!is.null(hugoopts)) {
52-
glue::glue_collapse(
53-
glue::glue('{names(hugoopts)}="{hugoopts}"'),
54-
sep = " "
55-
)
56-
},
57-
">}}\n"
58-
)
59-
}
39+
plot = function(x, options) modif_plot(x, options, dir_path = dir_path)
6040
)
61-
41+
knitr::opts_chunk$set(echo = FALSE)
6242
```
6343

6444
```{r, echo = FALSE, results = 'asis', include = TRUE, eval = TRUE}
@@ -150,3 +130,6 @@ Pour cela, on utilise les modules `spacy`, `Word2vec` et `Keras`
150130
import spacy
151131
nlp = spacy.load('en_core_web_sm')
152132
```
133+
134+
135+
TO BE CONTINUED

content/course/NLP/05_exo_supp.Rmd

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,10 @@ summary: |
3030

3131
```{r setup, include=FALSE}
3232
dir_path <- gsub(here::here(), "..", here::here("course","NLP"))
33-
34-
library(knitr)
35-
library(reticulate)
36-
knitr::knit_engines$set(python = reticulate::eng_python)
37-
knitr::opts_chunk$set(fig.path = "")
38-
knitr::opts_chunk$set(eval = TRUE, echo = FALSE, warning = FALSE, message = FALSE)
39-
40-
# Hook from Maelle Salmon: https://ropensci.org/technotes/2020/04/23/rmd-learnings/
4133
knitr::knit_hooks$set(
42-
plot = function(x, options) {
43-
hugoopts <- options$hugoopts
44-
paste0(
45-
"{", "{<figure src=", # the original code is simpler
46-
# but here I need to escape the shortcode!
47-
'"', paste0(dir_path,"/",x), '" ',
48-
if (!is.null(hugoopts)) {
49-
glue::glue_collapse(
50-
glue::glue('{names(hugoopts)}="{hugoopts}"'),
51-
sep = " "
52-
)
53-
},
54-
">}}\n"
55-
)
56-
}
34+
plot = function(x, options) modif_plot(x, options, dir_path = dir_path)
5735
)
58-
36+
knitr::opts_chunk$set(echo = FALSE)
5937
```
6038

6139
```{r, echo = FALSE, results = 'asis', include = TRUE, eval = TRUE}

content/course/NLP/06_elastic.Rmd

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,33 +33,10 @@ summary: |
3333

3434

3535
```{r setup, include=FALSE}
36-
dir_path <- gsub(here::here(), "..", here::here("course","manipulation"))
37-
38-
library(knitr)
39-
library(reticulate)
40-
knitr::knit_engines$set(python = reticulate::eng_python)
41-
knitr::opts_chunk$set(fig.path = "")
42-
knitr::opts_chunk$set(eval = TRUE, warning = FALSE, message = FALSE)
43-
44-
# Hook from Maelle Salmon: https://ropensci.org/technotes/2020/04/23/rmd-learnings/
36+
dir_path <- gsub(here::here(), "..", here::here("course","NLP"))
4537
knitr::knit_hooks$set(
46-
plot = function(x, options) {
47-
hugoopts <- options$hugoopts
48-
paste0(
49-
"{", "{<figure src=", # the original code is simpler
50-
# but here I need to escape the shortcode!
51-
'"', paste0(dir_path,"/",x), '" ',
52-
if (!is.null(hugoopts)) {
53-
glue::glue_collapse(
54-
glue::glue('{names(hugoopts)}="{hugoopts}"'),
55-
sep = " "
56-
)
57-
},
58-
">}}\n"
59-
)
60-
}
38+
plot = function(x, options) modif_plot(x, options, dir_path = dir_path)
6139
)
62-
6340
```
6441

6542
Pour essayer les exemples présents dans ce tutoriel :

0 commit comments

Comments
 (0)