Skip to content

Commit

Permalink
Utilisation d'un template issu d'un package (#229)
Browse files Browse the repository at this point in the history
* modif format out

* test gitbook

* retire quelques options

* retire quelques fichiers devenus inutiles

* autres fichiers inutiles

* build image avec docker

* ajout mention readme

* retire book.bib

* utiliser les nouveaux formats dans GHA c'est mieux 🙈

* retire typo branch name

* retire la compilation [skip ci]

* aère

* utilise package utilitr en prod ausso

* retour en arrière

* utilisation de paramètres par défaut dans utilitr::html_paged

* retire colorize function

* retire les fonctions print only

* retire les outputs conditionnels

* sortir quelques fonctions du .Rprofile

* retire code inutile

* retire actions pour préparer submodule

* Added CI/CD as submodule to the project.

* retire gitlab ci

* retire packages.bib

* retour à une version pas submodule

* besoin de var env

* retour du dir.create

* no need config.toml

* plus bvesoin de ces fiches

* rm fa dep

* rename fake package

* update link

* ajout un mot sur utilitr-template

* ajout dans rprofile
  • Loading branch information
linogaliana committed Feb 23, 2021
1 parent 56b1af6 commit 1b952b1
Show file tree
Hide file tree
Showing 24 changed files with 122 additions and 1,372 deletions.
82 changes: 7 additions & 75 deletions .Rprofile
@@ -1,28 +1,6 @@
if (file.exists('~/.Rprofile')) sys.source('~/.Rprofile', envir = environment())


colorize <- function(x, color) {
if (knitr::is_latex_output()) {
sprintf("\\textcolor{%s}{%s}", color, x)
} else if (knitr::is_html_output()) {
sprintf("<span style='color: %s;'>%s</span>", color,
x)
} else x
}


knitr::opts_chunk$set(out.width='75%', fig.align='center')
options(bookdown.render.file_scope = FALSE)

print_html_only <- function(x){
if (knitr::is_html_output()) return(x)
return("")
}

print_latex_only <- function(x){
if (knitr::is_latex_output()) return(x)
return("")
}

render_rmd <- function(x) return(cat(htmltools::includeText(x)))

Expand Down Expand Up @@ -78,70 +56,20 @@ add_space <- function(){

}

# needed for bookdown 0.20
options(bookdown.render.file_scope = FALSE)




# 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)
}
# Copier les images si elles ne sont pas déja dans le dossier

invisible(
file.copy(list.files(dossier_images, full.names = TRUE), dossier_images_compressees, recursive=TRUE, overwrite = TRUE)
)
compresser_image <-
function(file_in,
file_out = NA, ratio_compression = 2,
xmax = 300, quality = 0.7, cutoff = 3000) {
# Fonction de compression d'une image png
# xmax <- 1920 # y pixel max
# quality <- 0.7 # passed on to jpeg::writeJPEG()
# cutoff <- 100000 # files smaller than this will not be touched
# file_out <- "test.jpg"
if (is.na(file_out)) {
file_out <- sub(dossier_images, dossier_images_compressees, file_in)
}
if (is.na(file.size(file_in))) {
stop(paste0("File ", file_in, " not found."))
}
else if (file.size(file_in) < cutoff) { # in this case, just copy file
if (!(file_in == file_out)) {
file.copy(from = file_in, to = file_out, overwrite = TRUE)
}
} else {# if larger than cutoff
# magick workflow
image_raw <- magick::image_read(path = file_in)
if (!is.na(ratio_compression)) {
image_resized <-
magick::image_scale(
image = image_raw,
geometry = as.character(as.integer(round(magick::image_info(image_raw)["width"] / ratio_compression))))
} else if (magick::image_info(image_raw)["width"] > xmax) { # only resize if smaller
image_resized <-
magick::image_scale(
image = image_raw,
geometry = as.character(xmax))
} else {
image_resized <- image_raw
}
magick::image_write(image = image_resized,
path = file_out,
format = "png")
}
}

include_image <- function(x, compression = TRUE, ratio_compression = 2, ...) {
# Fonction qui 1/ compresse l'image si nécessaire; 2/ l'inclut dans le Rmd
if (compression) {
compresser_image(file_in = x, ...)
}
knitr::include_graphics(sub(dossier_images, dossier_images_compressees, x), ...)
}


reminder_image <- function(path = "moncheminperso"){
Expand All @@ -164,7 +92,11 @@ message(
"",
"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\")"),
" * Option 2: taper dans la commande R:
bookdown::render_book(\"index.Rmd\", output_dir = \"_public\", output_format = \"utilitr::html_document\")",
"",
"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"
)
)
2 changes: 1 addition & 1 deletion .github/workflows/bookdown-test.yaml
Expand Up @@ -25,7 +25,7 @@ jobs:
Rscript -e "install.packages(c('remotes'))"
Rscript -e "remotes::install_deps(dependencies = TRUE)"
- name: Render Book
run: Rscript -e 'bookdown::render_book("index.Rmd", output_dir = "_public")'
run: Rscript -e 'bookdown::render_book("index.Rmd", output_format = "utilitr::html_document", output_dir = "_public")'
- uses: actions/upload-artifact@v2
with:
name: _public
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/pagedown-test.yaml
Expand Up @@ -20,10 +20,9 @@ jobs:
- name: Render Book
run: |
mkdir _pagedown_output -p
Rscript -e "bookdown::render_book('index.Rmd', output_format = 'pagedown::html_paged', output_file = '_pagedown_output/index.html')"
Rscript -e "pagedown::chrome_print('_pagedown_output/index.html', '_pagedown_output/DocumentationR.pdf', extra_args = c('--disable-gpu', '--no-sandbox'), timeout = 600, options = list(transferMode = 'ReturnAsStream'), verbose = 1)"
Rscript -e "utilitr::pdf_document()"
- uses: actions/upload-artifact@v2
with:
name: DocumentationR_pagedown
path: _pagedown_output/DocumentationR.pdf
retention-days: 5
retention-days: 5
5 changes: 2 additions & 3 deletions .github/workflows/prod.yaml
Expand Up @@ -55,7 +55,7 @@ jobs:
Rscript -e "install.packages(c('remotes'))"
Rscript -e "remotes::install_deps(dependencies = TRUE)"
- name: Render Book
run: Rscript -e 'bookdown::render_book("index.Rmd", output_dir = "_public")'
run: Rscript -e 'bookdown::render_book("index.Rmd", output_dir = "_public", output_format = "utilitr::html_document")'
- uses: actions/upload-artifact@v2
with:
name: _public
Expand Down Expand Up @@ -92,8 +92,7 @@ jobs:
- name: Render Book
run: |
mkdir _pagedown_output -p
Rscript -e "bookdown::render_book('index.Rmd', output_format = 'pagedown::html_paged', output_file = '_pagedown_output/index.html')"
Rscript -e "pagedown::chrome_print('_pagedown_output/index.html', '_pagedown_output/DocumentationR.pdf', extra_args = c('--disable-gpu', '--no-sandbox'), timeout = 600, options = list(transferMode = 'ReturnAsStream'), verbose = 1)"
Rscript -e "utilitr::pdf_document()"
- uses: actions/upload-artifact@v2
with:
name: DocumentationR_pagedown
Expand Down
121 changes: 0 additions & 121 deletions .gitlab-ci.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .gitmodules
@@ -0,0 +1,3 @@
[submodule ".github"]
path = .github
url = https://github.com/InseeFrLab/utilitr-actions.git

0 comments on commit 1b952b1

Please sign in to comment.