---
title             : "The title"
shorttitle        : "Title"

author: 
  - name          : "First Author"
    affiliation   : "1"
    corresponding : yes    # Define only one corresponding author
    address       : "Postal address"
    email         : "my@email.com"
  - name          : "Ernst-August Doelle"
    affiliation   : "1,2"

affiliation:
  - id            : "1"
    institution   : "Wilhelm-Wundt-University"
  - id            : "2"
    institution   : "Konstanz Business School"

author_note: |
  Complete departmental affiliations for each author (note the indentation, if you start a new paragraph).

  Enter author note here.

abstract: |
  Enter abstract here (note the indentation, if you start a new paragraph).
  
keywords          : "keywords"
wordcount         : "X"

floatsintext      : yes
figurelist        : no
tablelist         : no
footnotelist      : no
linenumbers       : yes
mask              : no
draft             : no
citeproc          : no # To avoid CRAN check error

documentclass     : "apa6"
classoption       : "man"
output            : papaja::apa6_pdf
---

```{r message = FALSE, warning = FALSE}
library("papaja")
knitr::opts_chunk$set(echo = TRUE)
```

```{r}
my_table <- apply(cars, 2, function(x) # Create data
  round(c(Mean = mean(x), SD = sd(x), Min = min(x), Max = max(x)), 2)
)

apa_table(
  my_table[1, , drop = FALSE]
  , align = c("l", "r", "r")
  , caption = "0 Single row table."
  , note = "This table was created using apa_table()"
  , small = TRUE
  , placement = NULL
)
```

```{r}
apa_table(
  my_table
  , align = c("l", "r", "r")
  , caption = "1 A small table with custom number formatting."
  , note = "This table was created using apa_table()"
  , font_size = "small"
  , digits = 3
  , format.args = list(decimal.mark = ",", big.mark = "")
)
```


```{r}
apa_table(
  list(
    test = my_table
    , `moar test` = my_table
  )
  , align = c("l", "r", "r")
  , caption = "2 A tiny merged table (list of two) with added stub heading. Not escaped."
  , note = "This table was created using apa\\_table()"
  , added_stub_head = "Desciptives"
  , escape = FALSE
  , font_size = "tiny"
)
```

```{r}
apa_table(
  list(
    test = my_table
    , `moar test` = my_table
  )
  , align = c("l", "r", "r")
  , caption = "2.25 A merged table (list of two) with table spanners."
  , note = "This table was created using apa_table()"
  , added_stub_head = "Desciptives"
  , merge_method = "table_spanner"
)
```

```{r}
var_labelled <- as.data.frame(my_table)
variable_label(var_labelled) <- c(speed = "$\\alpha$", dist = "$\\beta$")

apa_table(
  list(
    test = var_labelled
    , `moar test` = var_labelled
  )
  , align = c("l", "r", "r")
  , caption = "2.5 A merged table (list of two) with added stub heading and variable labels. Not escaped."
  , note = "This table was created using apa\\_table()"
  , added_stub_head = "Desciptives"
  , escape = FALSE
)
```


```{r}
apa_table(
  list(
    test = my_table
  )
  , align = c("l", "r", "r")
  , caption = "3 A 'merged' table (list of one) with added stub heading."
  , note = "This table was created using apa_table()"
  , added_stub_head = "Desciptives"
)
```


```{r}
my_table2 <- my_table
rownames(my_table2) <- 1:nrow(my_table2)

apa_table(
  my_table2
  , align = c("l", "r", "r")
  , caption = "4 Test if simple row numbers are omitted from table."
  , note = "This table was created using apa_table()"
  , added_stub_head = "Desciptives"
)
```


```{r}
apa_table(
  list(A = my_table2, B = my_table2)
  , align = c("l", "r", "r")
  , caption = "5 Test if simple row numbers are omitted from merged table (list of two)."
  , note = "This table was created using apa_table()"
  , added_stub_head = "Desciptives"
)
```


```{r}
apa_table(
  list(A = my_table2[1:2, ], B = my_table2)
  , align = c("l", "r", "r")
  , caption = "5.25 Test if simple row numbers are omitted from merged table with unequal row numbers (list of two)."
  , note = "This table was created using apa_table()"
  , added_stub_head = "Desciptives"
)
```


```{r}
apa_table(
  list(A = cars[1:2, ], B = cars[3:6, ])
  , align = c("l", "r", "r")
  , caption = "5.25 Test if simple continued row numbers are omitted from merged table (list of two)."
  , note = "This table was created using apa_table()"
  , added_stub_head = "Desciptives"
)
```


```{r}
apa_table(
  list(A = cars[1:2, ], B = cars[5:7, ]
      )
  , align = c("l", "r", "r")
  , caption = "5.25 Test if simple discontinued row numbers are preserved from merged table(list of two)."
  , note = "This table was created using apa_table()"
  , added_stub_head = "Desciptives"
)
```

```{r}
apa_table(
  my_table
  , align = c("l", "r", "r")
  , caption = "6 Test of column spanner and stub indenting."
  , note = "This table was created using apa_table()."
  , row.names = TRUE
  , added_stub_head = "Desciptives"
  , col_spanners = list(Measure = c(2, 3))
  , stub_indents = list(2:3)
)
```

```{r}
my_table <- rbind(t(my_table), t(my_table), t(my_table))
rownames(my_table) <- 1:nrow(my_table)

apa_table(
  my_table
  , align = c("l", "r", "r")
  , caption = "7 Test of midurles and landscape mode and named stub indentation."
  , note = "This table was created using apa_table()."
  , added_stub_head = "Desciptives"
  , col_spanners = list(Measure = c(2, 3))
  , midrules = 4
  , stub_indents = list(c(1:2), Jo = c(4:6))
  , landscape = TRUE
)
```

```{r}
my_table <- rbind(my_table, my_table, my_table, my_table, my_table, my_table, my_table)
rownames(my_table) <- 1:nrow(my_table)

apa_table(
  my_table
  , align = c("l", "r", "r")
  , caption = "8 A long table."
  , note = "This table was created using apa_table()."
  , added_stub_head = "Desciptives"
  , col_spanners = list(Measure = c(2, 3))
  , midrules = 4
  , stub_indents = list(c(1:2), Jo = c(4:6))
  , longtable = TRUE
)
```

```{r}
apa_table(
  my_table
  , align = c("l", "r", "r")
  , caption = "9 A long table in landscape mode."
  , note = "This table was created using apa_table()."
  , added_stub_head = "Desciptives"
  , col_spanners = list(Measure = c(2, 3))
  , midrules = 4
  , stub_indents = list(c(1:2), Jo = c(4:6))
  , longtable = TRUE
  , landscape = TRUE
)
```


```{r}
counts <- c(18,17,15,20,10,20,25,13,12)
outcome <- gl(3,1,9)
treatment <- gl(3,3)
d.AD <- data.frame(treatment, outcome, counts)
glm.D93 <- glm(counts ~ outcome + treatment, family = poisson())

apa_table(
  apa_print(glm.D93)$table
  , align = "lrrrr"
  , escape = FALSE
)
```
