Multiple parameters
1. Multiple parameters
Let's add another parameter to the YAML header to increase efficiency when creating new files. Another piece of information we've specified in the document that we can use as a parameter is the fiscal year.2. Fiscal year
The data we've been using has information from the 2012 to 2018 fiscal years, and the fiscal year is defined as beginning July 1st of the previous year through June 30th of the year of interest. We've used the fiscal year in the report when filtering to create a plot of the projects within a particular year.3. Adding a parameter for fiscal year
Since we reference the fiscal year of interest in the report, let's add it as a parameter. Below the existing country parameter, we add fy for fiscal year, a colon and 2012. Remember, indentation is important.4. Adding parameters to define fiscal year
The fiscal year is defined by the start and end dates of the year. Let's also add these as parameters. Below the country parameter, we'll add a year_start parameter and a year_end parameter. The start date of the 2012 fiscal year is 2011-07-01 and the end date of the fiscal year is 2012-06-30. Notice that the dates are listed in quotations and we preserve the year-month-day format from the data. As before, we'll need to review each element of the document, the code, text, and YAML header, to ensure that the new report won't make incorrect references to previous versions of the report.5. Reviewing the code
While reviewing the code, we replace the date filter we used to create the plot of projects in a given fiscal year6. Reviewing the code
with params dollar sign year_start and params dollar sign year_end.7. Reviewing the code
We'll also rename any code chunks and objects that reference a particular fiscal year,8. Reviewing the code
remove the specific year, and use the word annual in the names instead, so that they will apply to new reports that summarize information about other fiscal years.9. Reviewing the text
Recall that we can modify the document to reference parameters in the text, headers, and YAML header of the report. Notice the specific references to a particular year in the text and header of the document.10. Reviewing the text
We can replace these instances with the fiscal year parameter using, in backticks, r params dollar sign fy.11. Reviewing the YAML header
After reviewing the YAML header and verifying that nothing else needs to be modified, we can run the file with the parameters.12. Knitting the report
Let's knit the file for the country Turkey and the fiscal year 2013. We change fy to 2013, the start date to 2012-07-01, and the end date to 2013-06-30. When we knit the file, we see the report has been updated with the new information.13. Let's practice!
Now that you can create a report using multiple parameters, let's practice!Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.