# Sweave Example 2 using a HTML file

Eric Lecoute
avr. 02, 2004

HTML Sweaving relies on R2HTML package, which uses CSS styles. Thus, you can change the whole aspect of your output, simply by changing the CSS file. Simply call:

    > Sweave("example2.snw", driver = RweaveHTML(), cssfile = "pastel.css")

You can insert scalars in text by using expressions <Sexpr expr>. If the result is a vector, only the first element is returned: see the call <Sexpr round(rnorm(10),2)> transformed to: 0.55. Also any HTML tag can be used to format this output: see this colored actual year computed by date(): 2004.

As we use HTML() functions, some formatting is already applied on most R objects. This this regression result:

- Call: lm(formula = y ~ x)
- Residuals

  -2.84356544970632 -1.83325602423836 -0.772809629352725 2.07696588557758 3.50616693306879

- Coefficients

  | Estimate | Std. Error | t value | Pr(>|t|) |
  --- | --- | --- | --- | --- | ---
  (Intercept) | 1.3586 | 1.6792 | 0.809 | 0.442 |
  x | 3.1321 | 0.2706 | 11.573 | 2.82e-06 | ***

  --- Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1

- Residuals standard error: 2.4581 on 8 degrees of freedom
- Multiple R-Squared:0.9436
- Adjusted R-Squared:0.9366
- F-statistics: 133.9432 on 1 and 8 DF. P-value:0.

  By default, the last manipulated object in a code chunk is evaluated and a call to HTML is done to catch it's HTML representation, which is inserted in the output file. You can override this behaviour by explicitely return a string containing HTML codes as output. This allows to have more controls on output, as you can do exactly what you want from R. To specify that output are already HTML, add the option `results=html` to your code chunk.

      > HTML(data.frame(x, y), digits = 2, Border = 2)

  | x | y
  --- | --- | ---
  1 | 1 | 4.4
  2 | 2 | 9.96
  3 | 3 | 7.91
  4 | 4 | 16.74
  5 | 5 | 14.92
  6 | 6 | 18.58
  7 | 7 | 21.83
  8 | 8 | 27.7
  9 | 9 | 33.05
  10 | 10 | 30.76

  Finally, some more options are added to handle graphs, such as `width`, `height`, `border`, `align` and `caption`

  Boxplot - x