Commit 219db682 authored by David Carayon's avatar David Carayon
Browse files

New 2.0 version with quarto templates

parent 0da34429
.Rproj.user
.Rhistory
.RData
.DS_Store
Package: InraeThemes
Title: Modèles et thèmes INRAE
Version: 1.0.1
Version: 2.0.0
Authors@R:
c(
person(given = "David",
......@@ -10,31 +10,23 @@ Authors@R:
person(given = "Sébastien",
family = "Boutry",
role = c("aut"),
email = "sebastien.boutry@inrae.fr"),
person(given = "Eric",
family = "Quinton",
role = c("ctb"),
email = "eric.quinton@inrae.fr")
email = "sebastien.boutry@inrae.fr")
)
Description: Ce package met à disposition des modèles de document ainsi que des thèmes ggplot suivant la charte graphique INRAE.
License: GPL-3
Description: Ce package met à disposition une collection non officielle de templates, thèmes et autres éléments graphiques basés sur des formats en lien avec R et en accords avec la charte graphique INRAE.
License: GPL (>= 3)
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.1
RoxygenNote: 7.1.2
Depends:
R (>= 2.10)
Imports:
ggplot2,
gt,
pagedown,
gert,
rmarkdown,
revealjs,
pagedown,
quarto,
scales,
xaringan,
xfun,
magrittr,
cli,
rstudioapi,
gridExtra,
bookdown
bslib,
thematic
......@@ -553,7 +553,7 @@ and each file should have at least the “copyright” line and a pointer to
where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 2020 David Carayon
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -573,7 +573,7 @@ Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short notice like this
when it starts in an interactive mode:
InraeThemes Copyright (C) 2020 David Carayon
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type 'show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type 'show c' for details.
......
# Generated by roxygen2: do not edit by hand
export(bookdown_inrae)
export(latex_presentation)
export(latex_report)
export(new_analysis)
export(bs_inrae)
export(create_presentation)
export(create_report)
export(palette_inrae)
export(scale_color_inrae)
export(scale_fill_inrae)
......
# InraeThemes 2.0.0
* Added a `NEWS.md` file to track changes to the package.
* Converted most of document templates from Rmarkdown to Quarto
* Converted separated outputs (PDF,Word,HTML) into single templates with complete YAML's
* New bslib theme for Shiny and Rmarkdown HTML documents
* New business card Rmarkdown template
* GPL-3 Licence
* Better README
File mode changed from 100644 to 100755
# bookdown_inrae <- function(dir = "MyProject"){
#
# if (!dir.exists(dir)) {dir.create(dir)}
#
# templates <- system.file("Bookdown_Inrae", package = "InraeThemes")
#
# file.copy(templates, dir, recursive = TRUE)
#
# setwd(file.path(dir,"Bookdown_Inrae"))
#
# cli::cli_alert_warning(paste0("Working directory changed to '", file.path(dir,"Bookdown_Inrae"),"'"))
#
# cli::cli_alert_info(paste0("Now opening '", "index.Rmd","'"))
# rstudioapi::navigateToFile("index.Rmd")
#
# }
#' Template Bookdown respectant la charte graphique INRAE
#'
#' @param dir Le dossier dans lequel copier le projet bookdown
#'
#' @return
#' @export
bookdown_inrae <- function(path, init = TRUE){
# If init
if(init) {gert::git_init(path)}
# ensure directory exists
dir.create(path, recursive = TRUE, showWarnings = FALSE)
# copy 'resources' folder to path
resources <- system.file(file.path("rstudio", "templates", "project", "resources"), package = "InraeThemes")
files <- list.files(resources, recursive = TRUE, include.dirs = FALSE)
source <- file.path(resources, files)
target <- file.path(path, files)
file.copy(source, target)
}
#' Architecture type d'une analyse
#' Inpiré du package `ProjectTemplate`
#'
#' @param projname Name of the project to be created
#' @param init Should a git repository be initialised ?
#'
#' @return
#' @export
new_analysis <- function(projname = "MyProject",init = TRUE){
# ensure path exists
dir.create(projname, recursive = TRUE, showWarnings = FALSE)
# Creating folders --------------------------------------------------------
dir.create(file.path(projname,"data"))
dir.create(file.path(projname,"cache"))
dir.create(file.path(projname,"docs"))
dir.create(file.path(projname,"img"))
dir.create(file.path(projname,"R"))
dir.create(file.path(projname,"report"))
# Should git init ? -------------------------------------------------------
if(init) {gert::git_init(projname)}
# Generating TODO ---------------------------------------------------------
file.create(file.path(projname,"TODO.txt"))
sink(file.path(projname,"TODO.txt"))
cat("Welcome!
Project name: N/A
Notes
-----
")
sink()
# Generating a README -----------------------------------------------------
file.create(file.path(projname,"README.md"))
sink(file.path(projname,"README.md"))
cat("> Welcome to Your project !
Description of the project's architecture :
- `README.md` : The intro file is used to provide project orientation. The file defines project objectives and is intended to introduce project data, source code and configurations for repeatable research. The md file format is that of a basic text or markdown file. When saved to GitHub, it will be used to create an HTML project wiki.
- `TODO.txt` : A note file on a project's development or implementation status with a list of bugs and future improvement needs.
- `cache` : The cache is used to store data output.
- `data` : The data directory stores all data inputs in raw format.
- `docs` : Here you can store any source or reference material about the project.
- `img` : Used to store image output, including Rplots, image files or gif animations.
- `R` : R source code (Plain R files or Rmd notebooks)
- `report` : Used to store output tables and reports. R is capable of supporting a broad range of outputs including Word, Powerpoint, pdf, LaTeX and HTML.")
sink()
# Generating a notebook ---------------------------------------------------
file.create(file.path(projname,"R","01_notebook.Rmd"))
sink(file.path(projname,"R","01_notebook.Rmd"))
cat("---
title: \"Titre de l'analyse\"
subtitle : \"Sous titre\"
author: \"Auteur\"
date: \"Dernière M.A.J : `r format(Sys.time(), '%d %B, %Y')`\"
output:
html_notebook:
toc: true
toc_float:
collapsed: false
smooth_scroll: true
toc_depth: 3
number_sections: true
---
# Intro
Cf. [sous section](#Equations).
Citer un article [@article] (Penser à inclure le .bib dans le YAML)
Cf. section [Analyse].
# Input
On charge certains packages :
```{r packages, message = FALSE}
library(InraeThemes)
library(xfun)
library(here)
library(ggplot2)
library(gt)
library(gridExtra)
```
# Gestion des chemins d'accès
Afin de proposer une analyse facilement reproductible par quiconque, nous conseillons l'utilisation du package {here} pour la gestion des chemins d'accès.
Par exemple, pour pointer vers un jeu de données on va préférer :
```{r chemins, message = FALSE}
chemin_data <- here::here('data','donnees.csv') # Good
chemin_data <- 'data/donnees.csv' # Bad
```
# Gestion de version
Nous recommandons vivement l'utilisation d'un système de gestion de versions tel que **git**. Pour plus d'informations, vous pouvez consulter l'article dédié à git sur [le site de Rstudio](https://support.rstudio.com/hc/en-us/articles/200532077-Version-Control-with-Git-and-SVN)
# Tableaux
`Vestibulum` imperdiet^[Nullam quis sem nunc], ex vel sodales facilisis, nibh tellus imperdiet massa, sit amet scelerisque orci velit vel tellus. Ut consequat justo tincidunt porttitor varius. Suspendisse erat ipsum, feugiat vitae rhoncus non, molestie ac purus. Morbi aliquet, elit eget blandit suscipit, est lacus facilisis turpis, nec fermentum nunc felis et lorem.
::: {#Table1}
Exemple de tableau avec {gt}
:::
```{r}
gt::gt(head(mtcars)) %>% gt::tab_options(table.width = pct(100))
```
## Equations
> Suspendisse potenti
Les formules LaTeX peuvent être utilisés au sein d'un paragraphe : $E=mc^2$ ou en tant qu'équation sur une ligne seule :
::: {#eq1}
:::
$$f=\\frac{a}{b+c}$$
----
Cras pulvinar ligula ac nisi porttitor, volutpat congue orci tincidunt. Pellentesque non mi congue, porta enim eget, venenatis sem. Integer suscipit vulputate tellus, eget commodo dolor gravida vel. Suspendisse gravida gravida ligula, in interdum sapien molestie ut.
### Graphiques
On reprend un des exemples proposés dans le README du package InraeThemes :
```{r example, message = FALSE, fig.width = 14, fig.height=8, dpi = 320}
## On charge les données d'exemple du package
data(\"example_datasets\")
## On construit 4 graphiques d'exemple, stockés dans une même liste
display <- list(
ggplot(example_datasets$www, aes_string(x = 'Minute', y = 'Users',
color = 'Measure',
shape = 'Measure')) +
geom_line() +
geom_point(size = 3) +
facet_wrap(~Measure) +
geom_point(size = 1.8) +
scale_color_inrae() +
scale_shape_manual(values = c(15, 16)) +
labs(title = \"Titre\", subtitle = \"Sous-titre\") +
theme_inrae(),
ggplot(example_datasets$cars, aes_string(x = 'mpg', fill = 'cyl',
colour = 'cyl')) +
geom_density(alpha = 0.75) +
scale_fill_inrae() +
scale_color_inrae() +
labs(fill = 'Cylinders', colour = 'Cylinders', x = 'MPG', y = 'Density') +
theme_inrae(),
ggplot(example_datasets$dia, aes_string(x = 'price', fill = 'cut')) +
geom_histogram(binwidth = 850) +
xlab('Price (USD)') +
ylab('Count') +
scale_fill_inrae() +
scale_x_continuous(label = function(x) paste0(x / 1000, 'k'))+
theme_inrae(),
ggplot(example_datasets$drivers, aes_string(x = 'Year', y = 'Deaths',
fill = \"Year\")) +
geom_boxplot(size = 0.25) +
ylab('Monthly Deaths') +
theme_inrae() +
scale_fill_inrae() +
coord_flip() +
labs(caption = \"Caption\")
)
# On assemble
do.call(gridExtra::grid.arrange, display)
```
# Conclusion
Pour conclure :
# R session info {-}
Pensez à inclure cette section afin d'indiquer l'état de votre machine lorsque vous avez réalisé cette analyse
```{r session info, comment=\"\"}
xfun::session_info()
```
# References {-}
")
sink()
}
#' Create a Quarto presentation template with INRAE theme
#'
#' @param dir the directory where the template will be copied to
#' @param change_dir should the working directory be changed to dir ?
#'
#' @return a quarto presentation template
#' @export
create_presentation <- function(dir = "inrae_presentation", change_dir = TRUE){
if (!dir.exists(dir)) {dir.create(dir)}
# Creating folders --------------------------------------------------------
path <- system.file("quarto/templates/inrae_presentation", package = "InraeThemes")
file.copy(list.files(path, full.names = TRUE), dir, recursive = TRUE)
cli::cli_alert_info(paste0("INRAE presentation template copied to'", paste0(dir,"/inrae_presentation","'")))
if(change_dir) {
setwd(file.path(dir))
cli::cli_alert_warning(paste0("Working directory changed to '", paste0(dir),"'"))
}
}
#' Create a Quarto report/book template with INRAE theme
#'
#'
#' @param dir the directory where the template will be copied to
#' @param change_dir should the working directory be changed to dir ?
#'
#' @return a quarto book template
#' @export
create_report <- function(dir = "inrae_report", change_dir = TRUE){
if (!dir.exists(dir)) {dir.create(dir)}
# Creating folders --------------------------------------------------------
path <- system.file("quarto/templates/inrae_report", package = "InraeThemes")
file.copy(list.files(path, full.names = TRUE), dir, recursive = TRUE)
cli::cli_alert_info(paste0("INRAE book/report template copied to'", paste0(dir,"/inrae_report","'")))
if(change_dir) {
setwd(file.path(dir))
cli::cli_alert_warning(paste0("Working directory changed to '", paste0(dir),"'"))
}
}
File mode changed from 100644 to 100755
#' Copy a LaTeX template for reports
#'
#' Template proposed by E. Quinton (INRAE/EABX)
#'
#' @param dir the directory where the template will be copied to
#'
#' @return a full latex template
#' @export
latex_report <- function(dir = "MyProject"){
if (!dir.exists(dir)) {dir.create(dir)}
# Creating folders --------------------------------------------------------
path <- system.file("Latex_templates/latex_report", package = "InraeThemes")
file.copy(path, dir, recursive = TRUE)
setwd(file.path(dir,"latex_report"))
cli::cli_alert_warning(paste0("Working directory changed to '", paste0(dir,"/latex_report","'")))
cli::cli_alert_info(paste0("Now opening '", "document_inrae.tex","'"))
rstudioapi::navigateToFile("document_inrae.tex")
}
#' Copy a LaTeX template for presentations
#'
#' Template proposed by E. Quinton (INRAE/EABX)
#'
#' @param dir the directory where the template will be copied to
#'
#' @return a full latex presentation template
#' @export
latex_presentation <- function(dir = "MyProject"){
if (!dir.exists(dir)) {dir.create(dir)}
# Creating folders --------------------------------------------------------
path <- system.file("Latex_templates/latex_presentation", package = "InraeThemes")
file.copy(path, dir, recursive = TRUE)
setwd(file.path(dir,"latex_presentation"))
cli::cli_alert_warning(paste0("Working directory changed to '", paste0(dir,"/latex_presentation","'")))
cli::cli_alert_info(paste0("Now opening '", "modele_beamer_inrae.tex","'"))
rstudioapi::navigateToFile("modele_beamer_inrae.tex")
}
......@@ -4,10 +4,6 @@
#'
#' @return un vecteur contenant les couleurs
#' @export
#'
#' @examples
#' library(InraeThemes)
#' palette_inrae()
palette_inrae <- function() {
c("inrae" = "#00a3a6",
"inrae_clair" = "#66c1bf",
......@@ -27,7 +23,7 @@ palette_inrae <- function() {
#'
#' @param ... Autres arguments pour \code{discrete_scale}.
#'
#' @return
#' @return a fill scale
#' @import scales
#' @export
scale_fill_inrae <- function(...){
......@@ -38,9 +34,10 @@ scale_fill_inrae <- function(...){
#'
#' @param ... Autres arguments pour \code{discrete_scale}.
#'
#' @return
#' @export
#' @return a color scale
#' @import scales
#' @export
scale_color_inrae <- function(...){
ggplot2::discrete_scale("color","inrae",scales::manual_pal(values = c("#00a3a6","#275662","#9dc544","#9ed6e3","#423089","#ed6e6c","#797870","#c4c0b3","#4e5352")), ...)
}
......@@ -3,12 +3,11 @@
#' Ce theme ggplot correspond aux couleurs issues de la charte graphique INRAE V3.
#'
#' @param base_size base size
#' @param base_family base family
#'
#' @return
#' @return a ggplot theme
#' @import ggplot2
#' @export
theme_inrae <- function(base_size = 15, base_family = "Avenir Next Pro") {
theme_inrae <- function(base_size = 15) {
# Global colors
blue <- palette_inrae()["inrae_bleu"]
......@@ -18,14 +17,14 @@ theme_inrae <- function(base_size = 15, base_family = "Avenir Next Pro") {
inrae <- palette_inrae()["inrae_fonce"]
inrae_sombre <- palette_inrae()["inrae_sombre"]
# Starts with theme_grey and then modify some parts
theme_grey(base_size = base_size, base_family = base_family) %+replace%
theme_grey(base_size = base_size) %+replace%
ggplot2::theme(
# Base Inherited Elements
line = ggplot2::element_line(colour = grey, size = 0.5, linetype = 1,lineend = "butt"),
rect = ggplot2::element_rect(fill = white, colour = blue,size = 0.5, linetype = 1),
text = ggplot2::element_text(family = base_family, face = "plain",
text = ggplot2::element_text(face = "plain",
colour = inrae_sombre, size = base_size,
lineheight = 0.9, hjust = 0.5, vjust = 0.5, angle = 0,
margin = ggplot2::margin(), debug = FALSE),
......@@ -69,3 +68,26 @@ theme_inrae <- function(base_size = 15, base_family = "Avenir Next Pro") {
complete = TRUE
)
}
#' Bootstrap Sass INRAE theme
#'
#' @return A Sass INRAE theme
#' @export
bs_inrae <- function() {
bslib::bs_theme(
version = 4,
bg = "#FFFFFF",
fg = "#275662",
primary = "#00a3a6",
secondary = "#275662",
success = "#9dc544",
info = "#9ed6e3",
warning = "#FFF100",
danger = "#ed6e6c",
base_font = "Avenir Next LT Pro",
heading_font = "Raleway",
code_font = "Fira Code"
)
}
This diff is collapsed.
This diff is collapsed.
File mode changed from 100644 to 100755
# Introduction {#intro}
You can label chapter and section titles using `{#label}` after them, e.g., we can reference Chapter \@ref(intro). If you do not manually label them, there will be automatic labels anyway, e.g., Chapter \@ref(methods).
Figures and tables with captions will be placed in `figure` and `table` environments, respectively.
```{r nice-fig, fig.cap='Here is a nice figure!', out.width='80%', fig.asp=.75, fig.align='center'}
par(mar = c(4, 4, .1, .1))
plot(pressure, type = 'b', pch = 19)
```
Reference a figure by its code chunk label with the `fig:` prefix, e.g., see Figure \@ref(fig:nice-fig). Similarly, you can reference tables generated from `knitr::kable()`, e.g., see Table \@ref(tab:nice-tab).
```{r nice-tab, tidy=FALSE}
knitr::kable(
head(iris, 20), caption = 'Here is a nice table!',
booktabs = TRUE
)
```
You can write citations, too. For example, we are using the **bookdown** package [@R-bookdown] in this sample book, which was built on top of R Markdown and **knitr** [@xie2015].
# Methods
We describe our methods in this chapter.
# Applications
Some _significant_ applications are demonstrated in this chapter.
## Example one
## Example two
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment