Skip to content

Commit

Permalink
Merge branch 'master' of github.com:EricMarcon/WorkingWithR
Browse files Browse the repository at this point in the history
  • Loading branch information
EricMarcon committed May 22, 2024
2 parents 30f13ee + 8fba41c commit 564d89f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
6 changes: 3 additions & 3 deletions 01-Software.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ The backup of this folder is managed elsewhere.
* A folder outside the home folder is used for source-controlled projects.
The user must have the right to write to it.
In the Windows organization, the folder corresponding to these criteria is `%LOCALAPPDATA%`, typically `C:\Users\Name\AppData`.
The folder will therefore be `%LOCALAPPDATA%\ProjectsR`.
To create it, run `md %LOCALAPPDATA%\ProjectsR` in a command prompt.
Pin this folder to the quick access of the file explorer (figure \@ref(fig:R-ProjetsR)): paste `%LOCALAPPDATA%\ProjetsR` in the address bar of the file explorer, validate, then right click on "Quick Access" and pin the folder.
The folder will therefore be `%LOCALAPPDATA%\RProjects`.
To create it, run `md %LOCALAPPDATA%\RProjects` in a command prompt.
Pin this folder to the quick access of the file explorer (figure \@ref(fig:R-ProjetsR)): paste `%LOCALAPPDATA%\RProjects` in the address bar of the file explorer, validate, then right click on "Quick Access" and pin the folder.

(ref:R-ProjetsR) Folder for projects under source control, on Windows.
```{r R-ProjetsR, fig.cap="(ref:R-ProjetsR)", echo=FALSE, out.width='100%'}
Expand Down
11 changes: 8 additions & 3 deletions 04-Writing.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -248,19 +248,19 @@ The horizontal `-` and vertical `|` separators allow to draw a table according t

Tables can also be produced by R code.
The content of the table is in a dataframe.
The `kable` function in the _knitr_ package prepares the table for display and passes the result to the `kable_styling` function in the _kableExtra_ package for final formatting.
The `kbl` function in the _kableExtra_ package prepares the table for display and passes the result to the `kable_styling` function for final formatting.

```{r kable, echo=TRUE, warning=FALSE}
library("tidyverse")
my_iris <- head(iris)
names(my_iris) <- c("Sepal length ($l_s$)", "Width", "Petal length", "Width", "Species")
knitr::kable(my_iris, caption="Table created by kable", booktabs = TRUE, escape = FALSE) %>%
kableExtra::kbl(my_iris, caption="Table created by kable", booktabs = TRUE, escape = FALSE) %>%
kableExtra::kable_styling(bootstrap_options = "striped", full_width = FALSE)
```

The caption is specified by the `caption` argument and referencing is possible because the table is given a label whose name is `tab:` followed by the name of the code snippet (table \@ref(tab:kable)).
As with the figures, an enhanced caption can be written in a separate paragraph.
A short caption for a possible list of tables (option `lot: true` in the header) is declared in the `caption.short` argument of `kable()`.
A short caption for a possible list of tables (option `lot: true` in the header) is declared in the `caption.short` argument of `kbl()`.

Always use the `booktabs = TRUE` argument so that the thickness of the separator lines is optimal in LaTeX.
Since the table contains mathematics (in the name of the first column), the `escape = FALSE` option is necessary.
Expand Down Expand Up @@ -1443,6 +1443,11 @@ If necessary, images can be produced in BMP (bitmap, without compression), JPEG

### Functions

ggplots can be saved to a file by the `ggsave()` function.
The extension of the file name sets its format.
See the help of the function for more details.

Other graphics require another method.
The `postscript()` function produces an EPS file.
The R code must call the function to create the file, produce the figure, and then close the file, for example:

Expand Down
8 changes: 0 additions & 8 deletions index.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,6 @@ InstallPackages <- function(Packages) {
# Basic packages
InstallPackages(c("bookdown", "formatR", "kableExtra", "magick", "ragg"))
# kableExtra must be loaded
if (knitr::opts_knit$get("rmarkdown.pandoc.to") == "docx") {
# Word output (https://stackoverflow.com/questions/35144130/in-knitr-how-can-i-test-for-if-the-output-will-be-pdf-or-word)
# Do not use autoformat (https://github.com/haozhu233/kableExtra/issues/308)
options(kableExtra.auto_format = FALSE)
}
library("kableExtra")
# Chunk font size hook: allows size='small' or any valid Latex font size in chunk options
def.chunk.hook <- knitr::knit_hooks$get("chunk")
knitr::knit_hooks$set(chunk = function(x, options) {
Expand Down

0 comments on commit 564d89f

Please sign in to comment.