6.1 Technical aspects
The workflow to create the report follow three steps:
- run the analysis and create a list with all results
- create a
.Rmd
template that will be shared by all locations - run
rmarkdown::render()
in order to generate report for each location
6.1.1 Run the analysis
6.1.1.1 Format data
data("data_model_GxE")
data_model_GxE = format_data_PPBstats(data_model_GxE, type = "data_agro")
## data has been formated for PPBstats functions.
6.1.1.2 Descriptive plots for each location
vec_locations = levels(data_model_GxE$location)
list_hist_locations = lapply(
vec_locations, function(x){
p = plot(
data_model_GxE, plot_type = "histogramm",
vec_variables = c("y1")
)
p$y1
}
)
names(list_hist_locations) = vec_locations
Note that it is important that each element of the list refers to data of a given location in order to catch the right information in the next step when generating the report.
6.1.1.3 GGE model for all locations
The function workflow_gxe()
is coming from section 3.6.3.
vec_variables = c("y1")
res_gge = lapply(vec_variables, workflow_gxe, "GGE")
## GGE model done for y1
names(res_gge) = vec_variables
6.1.1.4 Create a list with all results
res = list("hist_locations" = list_hist_locations,
"res_gge" = res_gge
)
6.1.2 Create a .Rmd
template
Your template call two objects:
params
which is list with parameter of the reportres
which is a list with all results coming from the analysis
Below is an example of a minimal template:
---
title: "`r params$title`"
date: "`r format(Sys.time(), '%d %B %Y')`"
author: Flower Seed
output:
html_document:
toc: TRUE
toc_float: TRUE
---
```{r global_options,include=FALSE}
knitr::opts_chunk$set(echo=FALSE, warning=FALSE, message=FALSE)
```
# Introduction
Here is a beautiful report with all results of the year !
# Description of data on the location
```{r}
p = res$hist_locations[[location]]
if(is.null(p)){print("No data for y1")}else {p}
```
# GGE analysis for the three locations
The germplasm effects are the following:
```{r}
res$res_gge$y1$p_out_mean_comparisons_gxe$germplasm
```
The which won where plot is the following:
```{r}
res$res_gge$y1$p_out_biplot_gxe$biplot$which_won_where
```
6.1.3 Generate a report for each location
To generate the report, you need the R
package rmarkdown
installed.
In the following example, the output is .html
.
You can choose .pdf
or .docx
.
See ?rmarkdown::render
for more information.
library(rmarkdown)
vec_locations = names(res$hist_locations)
for (location in vec_locations){ # For each location, render a report
params = list("title" = paste("Agronomic analyses for", location))
rmarkdown::render("./template.Rmd",
output_file = paste("report_", location, "_", ".html", sep = ""),
output_dir = "."
)
}
The report generated can be visualized for loc-1, loc-2 and loc-3.
More examples of worklows with script, template and outputs can be found here.