forked from eusebe/ascii
/
test-1-Rmd.Rmd
76 lines (62 loc) · 1.43 KB
/
test-1-Rmd.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
---
title: "A Test File"
author: "Friedrich Leisch (adapted by Mark Clements)"
output:
html_document:
toc: TRUE
---
We load the `ascii` package and set the output type as `"pandoc"`.
```{r setup}
library(ascii)
options(asciiType="pandoc")
```
A simple example: the integers from 1 to 10 are
```{r integers,results='asis'}
ascii(1:10)
```
```{r testing, include=FALSE}
print(1:20)
```
<!-- the above is just to ensure that 2 code chunks can follow each other -->
We can also emulate a simple calculator:
```{r}
1 + 1
1 + pi
sin(pi/2)
```
Now we look at Gaussian data:
```{r, results='asis'}
library(stats)
set.seed(12345)
ascii(x <- rnorm(20))
ascii(t1 <- t.test(x))
```
Note that we can easily integrate some numbers into standard text: The
third element of vector `x` is `r x[3]`, the
_p_-value of the test is `r format.pval(t1$p.value)`.
Now we look at a summary of the famous `iris` data set, and we
want to see the commands in the code chunks:
```{r, results='asis'}
data(iris)
ascii(summary(iris),header=TRUE)
```
```{r,fig.cap="Pairs plot of the iris data"}
library(graphics)
pairs(iris)
```
```{r,fig.cap="Boxplot of sepal length grouped by species"}
boxplot(Sepal.Length~Species, data=iris)
```
Finally, we test the new `asciiCoefmat` function:
```{r, results='asis'}
library(stats)
x = y = 1:10
y[1] = 5
lm(y ~ x) |> summary() |> coef() |> asciiCoefmat()
```
```{r}
library(stats)
x = y = 1:10
y[1] = 5
lm(y ~ x) |> summary()
```