I have an R markdown file that automatically generates a report, the problem is that the output file is the R file name so every time that i change the client and generate a new report it eliminates the report generated before, i need to save the output file as Name_LastName_Month_Year.
The Name and the LastName variables are declared in a code chunk bellow the YAML header, the Month and the Year are params declared in the header
The output file is a pdf.
output:
pdf_document: default
```{r}
# Load necessary packages
library(ggplot2)
library(rmarkdown)
# Get the variable names from mtcars
params <- names(mtcars)
# Generate reports for each variable
for (i in seq_along(params)) {
param <- params[i]
# Generate the plot
plot <- ggplot(mtcars, aes_string(x = "mpg", y = param)) +
geom_point() +
labs(title = paste("Scatter Plot of mpg vs.", param),
x = "mpg",
y = param)
plot
# Generate the report
report_file <- paste0("report_", i, ".pdf")
rmarkdown::render(input = "example.Rmd",output_file = report_file)
}
```
The optimal result would be to generate the report and to have the output file with the name: investorname_investorlastname_month_year.pdf