5  Parameterized Documents

5.1 Parameters

Treat params as a list, access with params$___

  • Use plot_color for the color of the points in the plot

  • Only plot data from specified year

  • Use interactive (logical) to determine whether to use ggplotly

Tips:

  • If using parameters, make sure to print(params) so you know what you’re looking at later.

  • If using parameters, change the output-file in the YAML as well so you don’t overwrite old reports.

print(params)
$interactive
[1] TRUE

$year
[1] 2007

$plot_color
[1] "pink"

$show_code
[1] FALSE

5.2 Parameterized Plot

5.3 Parameterized Analysis

A linear model of life expectancy as a function of GDP per capita in the year 2007:


Call:
lm(formula = lifeExp ~ gdpPercap, data = gapminder %>% filter(year == 
    params$year))

Residuals:
    Min      1Q  Median      3Q     Max 
-22.828  -6.316   1.922   6.898  13.128 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept) 5.957e+01  1.010e+00   58.95   <2e-16 ***
gdpPercap   6.371e-04  5.827e-05   10.93   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 8.899 on 140 degrees of freedom
Multiple R-squared:  0.4606,    Adjusted R-squared:  0.4567 
F-statistic: 119.5 on 1 and 140 DF,  p-value: < 2.2e-16