README.md

stp25output

Die Scripten dienen der Erstellung von Reports als HTML aber auch von PDF ueber knit. Zum Teil handelt es sich um modifizerte Funktionen von R2HTML, texreg und htmlTable.

Overview

Output formats

| File | Type | Parameter | which_output() | | ---- | --------------- | ---------------- | --------------- | | r | | | text | | r | Projekt(“html”) | | html | | r | spin | html_document | markdown_html | | r | spin | pdf_document | latex | | r | spin | word_document | docx | | Rmd | | html_document | markdown_html | | Rmd | | pdf_document | latex | | Rmd | | word_document | docx | | Rmd | | beamer | latex | | Rmd | | github_document | markdown_html |

Projekt

Initialisieren eines Projektes.

# devtools::install_github("stp4/stp25output")
get_my_options()$output
#> [1] ""
which_output()
#> [1] "markdown_html"
Projekt("md", "Beispiel Projekt",
        datum = date(),
        fig_folder = "Fig",
        html_folder = "Results",
        OutDec = NULL,
        contrasts =  c("contr.Treatment", "contr.poly")
        )
#> 
#> Kontraste von  contr.treatment, contr.poly auf
#>  contr.Treatment, contr.poly  umgestellt!
#> 
#> set: output = md
get_my_options()$output
#> [1] "md"
which_output()
#> [1] "markdown"

set_my_options(prozent=list(digits=c(1,0), style=2))
set_lattice_ggplot()
# Optionen format:  HTML, Spin, Knit, Rpres oder Text
APA2(.~ gruppe , hkarz, caption="Deskriptive Analyse")
#> 
#> 
#> |Item  |N  |krank (n=24) |gesund (n=21) |
#> |:-----|:--|:------------|:-------------|
#> |tzell |45 |63.85 (5.61) |71.27 (4.84)  |
#> |lai   |45 |0.12 (0.34)  |0.76 (0.44)   |

End()
#> Warning in HTMLGetFile(): not default HTML output file defined; please call
#> HTMLSetFile2() to set it
#> 
#> Reset Kontraste

Usage

data.frame()

get_my_options()$output

[1] ""

which_output()

[1] “markdown_html”


dat<- data.frame(
term = c("A", "B", "C", "D"),
n = c(23, 14, 56, 2),
m = c("4.7 (2.4)", "4.1 (2.3)", "8.9 (3.6)", NA)
) 

dat  %>% Output("data.frame()")
Tab 1: data.frame() Quelle n m A 23 4.7 (2.4) B 14 4.1 (2.3) C 56 8.9 (3.6) D 2

matrix(c("a1","a2",3,4,5,6),
                nrow=2, byrow=TRUE,
                dimnames=list(gender=c("M", "F"),
                              party=c( "Dem", "Ind", "Rep")))  #%>% Output("matrix()")
  party

gender Dem Ind Rep M “a1” “a2” “3” F “4” “5” “6”


as.table(matrix(c("a1","a2",3,4,5,6),
                 nrow=2, byrow=TRUE,
                 dimnames=list(gender=c("M", "F"),
                               party=c( "Dem", "Ind", "Rep")))) %>% Output("as.table()")
Tab 2: as.table()   party gender   Dem Ind Rep M   a1 a2 3 F   4 5 6

Tabelle2(hkarz,  tzell, lai, gruppe, APA=TRUE )
Tab 3: Charakteristik Item n m tzell (mean) 45 67.31 (6.41) lai (mean) 45 0.42 (0.50) gruppe  45  krank 53% (24)  gesund 47% (21)
res<-  Tabelle(hkarz,  tzell, lai, gruppe, APA=TRUE)
Output(res, add_row =c("<b>Erste Zeile</b>" = 1, "Dritte Zeile" = 3) )
Tab 4: Charakteristik Item n m Erste Zeile tzell (mean) 45 67.31 (6.41) lai (mean) 45 0.42 (0.50) Dritte Zeile gruppe  45  krank 53% (24)  gesund 47% (21)
get_my_options()$output
#> [1] ""
which_output()
#> [1] "markdown_html"
#+ 
df1 %>% Output()
#> <table class='gmisc_table' style='border-collapse: collapse; padding-left: .5em; padding-right: .2em;' >
#> <thead>
#> <tr><td colspan='3' style='text-align: left;'>
#> Tab 5: </td></tr>
#> <tr>
#> <th style='border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: center;'>Quelle</th>
#> <th style='border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: center;'>n</th>
#> <th style='border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: center;'>m</th>
#> </tr>
#> </thead>
#> <tbody>
#> <tr>
#> <td style='padding-left: .5em; padding-right: .2em; text-align: left;'>A</td>
#> <td style='padding-left: .5em; padding-right: .2em; text-align: left;'>23</td>
#> <td style='padding-left: .5em; padding-right: .2em; text-align: left;'>4.7&nbsp;(2.4)</td>
#> </tr>
#> <tr>
#> <td style='padding-left: .5em; padding-right: .2em; text-align: left;'>B</td>
#> <td style='padding-left: .5em; padding-right: .2em; text-align: left;'>14</td>
#> <td style='padding-left: .5em; padding-right: .2em; text-align: left;'>4.1&nbsp;(2.3)</td>
#> </tr>
#> <tr>
#> <td style='padding-left: .5em; padding-right: .2em; text-align: left;'>C</td>
#> <td style='padding-left: .5em; padding-right: .2em; text-align: left;'>56</td>
#> <td style='padding-left: .5em; padding-right: .2em; text-align: left;'>8.9&nbsp;(3.6)</td>
#> </tr>
#> <tr>
#> <td style='padding-left: .5em; padding-right: .2em; border-bottom: 2px solid grey; text-align: left;'>D</td>
#> <td style='padding-left: .5em; padding-right: .2em; border-bottom: 2px solid grey; text-align: left;'>2</td>
#> <td style='padding-left: .5em; padding-right: .2em; border-bottom: 2px solid grey; text-align: left;'></td>
#> </tr>
#> </tbody>
#> <tfoot><tr><td colspan='3'>
#> </td></tr></tfoot>
#> </table>


df1 %>% Output(output=TRUE)
#> 
#>  Tab 6:  
#>   Quelle  n         m
#> 1      A 23 4.7 (2.4)
#> 2      B 14 4.1 (2.3)
#> 3      C 56 8.9 (3.6)
#> 4      D  2      <NA>
#> 
#> 

df1 %>% Output(output=FALSE)
#> NULL

df1 %>% Output()
Tab 7: Quelle n m A 23 4.7 (2.4) B 14 4.1 (2.3) C 56 8.9 (3.6) D 2

df1 %>% Output(output="text")
#> 
#>  Tab 8:  
#>   Quelle  n         m
#> 1      A 23 4.7 (2.4)
#> 2      B 14 4.1 (2.3)
#> 3      C 56 8.9 (3.6)
#> 4      D  2      <NA>
#> 
#> 

df1 %>% Output(output="markdown")

| Quelle | n | m | | :----- | -: | :-------- | | A | 23 | 4.7 (2.4) | | B | 14 | 4.1 (2.3) | | C | 56 | 8.9 (3.6) | | D | 2 | |

xtable()

Ist eine Package zum Erstellen von HTML und latex. Convert an R object to an xtable object, which can then be printed as a LaTeX or HTML table


require(xtable)
#> Loading required package: xtable
data(tli)
## Demonstrate aov
fm1 <- aov(tlimth ~ sex + ethnicty + grade + disadvg, data = tli)
fm1.table <- xtable(fm1)

Output(fm1.table)
Tab 9: Analysis of Variance Table Response: tlimth Quelle Df Sum Sq Mean Sq F Pr(\>F) sex 1 75.37 75.37 0.38 0.5417 ethnicty 3 2572.15 857.38 4.27 0.0072 grade 1 36.31 36.31 0.18 0.6717 disadvg 1 59.30 59.30 0.30 0.5882 Residuals 93 18682.87 200.89

fm2 <- lm(tlimth ~ sex*ethnicty, data = tli)
fm2b <- lm(tlimth ~ ethnicty, data = tli)

#Output(xtable(anova(fm2b, fm2)), output="md")

knitr::kable

knitr::kable(
  df1, row.names = FALSE,
  format = "pandoc" 
)

| term | n | m | | :--- | -: | :-------- | | A | 23 | 4.7 (2.4) | | B | 14 | 4.1 (2.3) | | C | 56 | 8.9 (3.6) | | D | 2 | NA |


knitr::kable(
  df1, row.names = FALSE,
  format = "markdown" 
)

| term | n | m | | :--- | -: | :-------- | | A | 23 | 4.7 (2.4) | | B | 14 | 4.1 (2.3) | | C | 56 | 8.9 (3.6) | | D | 2 | NA |

knitr::kable(
  df1, row.names = FALSE,
  format = "pandoc" 
)

| term | n | m | | :--- | -: | :-------- | | A | 23 | 4.7 (2.4) | | B | 14 | 4.1 (2.3) | | C | 56 | 8.9 (3.6) | | D | 2 | NA |

Grafik settings

require(stpvers)
set.seed(2)
n <- 20 * 3 * 2
DF <- data.frame(
  n = runif(n, min = 1, max = 5),
  e = runif(n, min = 1, max = 5),
  o = runif(n, min = 1, max = 5),
  g = runif(n, min = 1, max = 5),
  a = runif(n, min = 1, max = 5),
  treatment = gl(3, n / 3, labels = c("UG1", "UG2", "KG"))[sample.int(n)],
  sex = gl(2, n / 2, labels = c("male", "female"))
)
set_lattice()
bwplot2(e ~ treatment,
        DF,
        groups = sex,
        auto.key = list(columns = 2))


set_lattice_ggplot()
bwplot2(e ~ treatment,
        DF,
        groups = sex,
        auto.key = list(columns = 2))

set_lattice_bw()
bwplot2(e ~ treatment,
        DF,
        groups = sex,
        auto.key = list(columns = 2))



reset_lattice()

A few methods for making tables in rmarkdown

Quelle: https://gist.github.com/benmarwick/8ad99f35d5e4caa06492

https://github.com/yihui/printr https://github.com/jalapic/simpletable https://github.com/renkun-ken/formattable

my_data <- head(iris)
names(my_data) <- c(letters[1:ncol(iris)])
library("knitr")
kable(my_data)
a b c d e 5.1 3.5 1.4 0.2 setosa 4.9 3.0 1.4 0.2 setosa 4.7 3.2 1.3 0.2 setosa 4.6 3.1 1.5 0.2 setosa 5.0 3.6 1.4 0.2 setosa 5.4 3.9 1.7 0.4 setosa
library("xtable")
print(xtable(my_data), type = "html", include.rownames=FALSE, html.table.attributes=list("border='0' cellpadding='5' "))
a b c d e 5.10 3.50 1.40 0.20 setosa 4.90 3.00 1.40 0.20 setosa 4.70 3.20 1.30 0.20 setosa 4.60 3.10 1.50 0.20 setosa 5.00 3.60 1.40 0.20 setosa 5.40 3.90 1.70 0.40 setosa
library(xtable)
print(xtable(my_data), type = 'html')
a b c d e 1 5.10 3.50 1.40 0.20 setosa 2 4.90 3.00 1.40 0.20 setosa 3 4.70 3.20 1.30 0.20 setosa 4 4.60 3.10 1.50 0.20 setosa 5 5.00 3.60 1.40 0.20 setosa 6 5.40 3.90 1.70 0.40 setosa
library(xtable)
print(xtable(my_data), type = 'html', html.table.attributes = '')
a b c d e 1 5.10 3.50 1.40 0.20 setosa 2 4.90 3.00 1.40 0.20 setosa 3 4.70 3.20 1.30 0.20 setosa 4 4.60 3.10 1.50 0.20 setosa 5 5.00 3.60 1.40 0.20 setosa 6 5.40 3.90 1.70 0.40 setosa
library("pander")
pandoc.table(my_data)

| a | b | c | d | e | | :-: | :-: | :-: | :-: | :----: | | 5.1 | 3.5 | 1.4 | 0.2 | setosa | | 4.9 | 3 | 1.4 | 0.2 | setosa | | 4.7 | 3.2 | 1.3 | 0.2 | setosa | | 4.6 | 3.1 | 1.5 | 0.2 | setosa | | 5 | 3.6 | 1.4 | 0.2 | setosa | | 5.4 | 3.9 | 1.7 | 0.4 | setosa |

library("pander")
pandoc.table(my_data, split.cells = 5)

| a | b | c | d | e | | :-: | :-: | :-: | :-: | :----: | | 5.1 | 3.5 | 1.4 | 0.2 | setosa | | 4.9 | 3 | 1.4 | 0.2 | setosa | | 4.7 | 3.2 | 1.3 | 0.2 | setosa | | 4.6 | 3.1 | 1.5 | 0.2 | setosa | | 5 | 3.6 | 1.4 | 0.2 | setosa | | 5.4 | 3.9 | 1.7 | 0.4 | setosa |

pander::panderOptions('table.split.table', 350)
pander::pandoc.table(my_data, style="rmarkdown")

| a | b | c | d | e | | :-: | :-: | :-: | :-: | :----: | | 5.1 | 3.5 | 1.4 | 0.2 | setosa | | 4.9 | 3 | 1.4 | 0.2 | setosa | | 4.7 | 3.2 | 1.3 | 0.2 | setosa | | 4.6 | 3.1 | 1.5 | 0.2 | setosa | | 5 | 3.6 | 1.4 | 0.2 | setosa | | 5.4 | 3.9 | 1.7 | 0.4 | setosa |

library("ascii")
print(ascii(my_data), type = 'pandoc')
library("htmlTable")
htmlTable(my_data, col.rgroup = c("none", "#F7F7F7"))
a b c d e 1 5.1 3.5 1.4 0.2 setosa 2 4.9 3 1.4 0.2 setosa 3 4.7 3.2 1.3 0.2 setosa 4 4.6 3.1 1.5 0.2 setosa 5 5 3.6 1.4 0.2 setosa 6 5.4 3.9 1.7 0.4 setosa
library(hwriter)
hwrite(my_data, border=0)

[1] "

a b c d e 1 5.1 3.5 1.4 0.2 setosa 2 4.9 3.0 1.4 0.2 setosa 3 4.7 3.2 1.3 0.2 setosa 4 4.6 3.1 1.5 0.2 setosa 5 5.0 3.6 1.4 0.2 setosa 6 5.4 3.9 1.7 0.4 setosa

"

This one is the most useful, and has a nice guide to customisation here: http://www.ebi.ac.uk/~gpau/hwriter/

library(hwriter)
cat(hwrite(my_data, border = 0, center=TRUE, table.frame='void', width='300px', table.style='padding: 50px', row.names=FALSE, row.style=list('font-weight:bold')))

a b c d e 5.1 3.5 1.4 0.2 setosa 4.9 3.0 1.4 0.2 setosa 4.7 3.2 1.3 0.2 setosa 4.6 3.1 1.5 0.2 setosa 5.0 3.6 1.4 0.2 setosa 5.4 3.9 1.7 0.4 setosa



stp4/stp25output documentation built on Sept. 19, 2021, 11:56 a.m.