Running examples in ‘agriTutorial-Ex.R’ failed
The error most likely occurred in:

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: example2
> ### Title: Example 2: Lack-of-fit and marginality for a single quantitative
> ###   treatment factor
> ### Aliases: example2
> 
> ### ** Examples
> 
> 
> ## *************************************************************************************
> ##                       How to run the code
> ## *************************************************************************************
> 
> ## Either type example("example2") to run ALL the examples succesively
> ## or copy and paste examples sucessively, as required
> 
> ## *************************************************************************************
> ##                         Options and required packages
> ## *************************************************************************************
> 
> options(contrasts = c('contr.treatment', 'contr.poly'))
> ## ggplot2 MUST be installed
> require(ggplot2)
Loading required package: ggplot2
> 
> ## *************************************************************************************
> ##         Polynomial analysis and graphical plots of factorial treatment effects
> ## *************************************************************************************
> 
> N = poly((beet$nrate/100), degree = 4, raw = TRUE)
> colnames(N) = c("Linear_N", "Quadratic_N", "Cubic_N", "Quartic_N")
> beet = cbind(beet, N)
> 
> ## Tables 4 and 5: Full polynomial analysis of variance based on raw polynomials
> anova(lm(yield ~ Replicate + Linear_N + Quadratic_N + Cubic_N + Quartic_N, data = beet))
Analysis of Variance Table

Response: yield
            Df Sum Sq Mean Sq  F value    Pr(>F)    
Replicate    2  26.32   13.16   3.7118   0.07238 .  
Linear_N     1 651.47  651.47 183.7364 8.429e-07 ***
Quadratic_N  1 260.50  260.50  73.4710 2.649e-05 ***
Cubic_N      1   1.59    1.59   0.4476   0.52232    
Quartic_N    1   0.00    0.00   0.0011   0.97450    
Residuals    8  28.37    3.55                       
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> 
> ##  Table 6: showing quadratic model coefficients with standard errors and confidence intervals
> quadratic = lm(yield ~ Replicate + Linear_N + Quadratic_N, data = beet)
> summary(quadratic)

Call:
lm(formula = yield ~ Replicate + Linear_N + Quadratic_N, data = beet)

Residuals:
    Min      1Q  Median      3Q     Max 
-2.6705 -0.9457  0.2495  0.7852  2.5991 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)    9.139      1.133   8.066 1.10e-05 ***
Replicate2    -0.720      1.095  -0.658   0.5256    
Replicate3     2.380      1.095   2.174   0.0548 .  
Linear_N      41.777      3.183  13.125 1.25e-07 ***
Quadratic_N  -20.330      2.180  -9.325 3.00e-06 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 1.731 on 10 degrees of freedom
Multiple R-squared:  0.9691,	Adjusted R-squared:  0.9567 
F-statistic: 78.31 on 4 and 10 DF,  p-value: 1.657e-07

> confint(quadratic, level = 0.95)
                 2.5 %     97.5 %
(Intercept)   6.614421  11.663674
Replicate2   -3.159021   1.719021
Replicate3   -0.059021   4.819021
Linear_N     34.684891  48.868850
Quadratic_N -25.188052 -15.472784
> 
> par(mfrow = c(2, 2), oma = c(0, 0, 2, 0))
> plot(quadratic, sub.caption = NA)
> title(main = "Diagnostic plots for quadratic nitrogen effects model", outer = TRUE)
> 
> ggplot(beet, aes(x = nrate, y = yield)) +
+  ggtitle("Fig 3 Yield versus N for sugar beet with 95% confidence band") +
+  geom_point(shape = 1) + stat_summary(fun.y = mean, geom = "point") +
+  geom_smooth(method = lm, formula = y ~ poly(x, 2)) + theme_bw()
Error in grid.Call.graphics(C_setviewport, vp, TRUE) : 
  VECTOR_ELT() can only be applied to a 'list', not a 'double'
Calls: <Anonymous> ... lapply -> FUN -> push.vp.viewport -> grid.Call.graphics
Execution halted