---
title: "rjdmarkdown with PDF output"
output: 
   pdf_document:
      keep_tex: true
header-includes:
   - \usepackage{booktabs}
   - \usepackage{float}
   - \usepackage{array}
   - \usepackage{multirow}
   - \floatplacement{figure}{H}
vignette: >
  %\VignetteIndexEntry{rjdmarkdown with PDF output}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(collapse = TRUE,
  comment = "#>", fig.pos = "h",
  warning = FALSE, message = FALSE
)
```

The functions developped in `rjdmarkdown` are:

- `print_preprocessing()` for the pre-processing model;  
- `print_decomposition()` for the decomposition;  
- `print_diagnostics()` to print diagnostics tests on the quality of the seasonal adjustment.

The result is different between X-13ARIMA and TRAMO-SEATS models.

```{r}
library(rjdmarkdown)
library(RJDemetra)
sa_x13 <- x13(ipi_c_eu[, "FR"])
sa_ts <- tramoseats(ipi_c_eu[, "FR"])
```

# X-13-ARIMA model

```{r, results='asis', fig.cap = "S-I Ratio"}
print_preprocessing(sa_x13, format = "latex")
print_decomposition(sa_x13, format = "latex", caption = NULL)
print_diagnostics(sa_x13, format = "latex")
```

# TRAMO-SEATS model

Some others graphics can also be added with the [`ggdemetra`](https://aqlt.github.io/ggdemetra/) package, for example to add the seasonally adjusted series and its forecasts:

```{r, results='asis', fig.cap = c("Seasonal adjustment of the French industrial production index", "S-I Ratio")}
library(ggdemetra)
ggplot(data = ipi_c_eu_df, mapping = aes(x = date, y = FR)) +
    geom_line() +
    labs(title = NULL,
         x = NULL, y = NULL) +
    geom_sa(component = "y_f", linetype = 2,
            frequency = 12, method = "tramoseats") + 
    geom_sa(component = "sa", color = "red") +
    geom_sa(component = "sa_f", color = "red", linetype = 2)
print_preprocessing(sa_ts, format = "latex")
print_decomposition(sa_ts, format = "latex", caption = NULL)
print_diagnostics(sa_ts, format = "latex")
```

# Reproductibility

For PDF outputs, the package `booktabs` and `float` must be used.

```{r, eval = FALSE}
header-includes:
   - \usepackage{booktabs}
   - \usepackage{float}
   - \floatplacement{figure}{H}
```

To produce this document, the `knitr` options were set as followed:

```{r, include = TRUE, eval = FALSE}
knitr::opts_chunk$set(collapse = TRUE,
  comment = "#>", fig.pos = "h",
  warning = FALSE, message = FALSE
)
```

And the options `results='asis', fig.cap = "S-I Ratio"` were used in the chunks.