knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "README-"
)

require(stpvers)

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
which_output()
Projekt("md", "Beispiel Projekt",
        datum = date(),
        fig_folder = "Fig",
        html_folder = "Results",
        OutDec = NULL,
        contrasts =  c("contr.Treatment", "contr.poly")
        )
get_my_options()$output
which_output()

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")

End()

Usage

data.frame()

get_my_options()$output
which_output()

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()")
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()")

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()")
Tabelle2(hkarz,  tzell, lai, gruppe, APA=TRUE )
res<-  Tabelle(hkarz,  tzell, lai, gruppe, APA=TRUE)
Output(res, add_row =c("<b>Erste Zeile</b>" = 1, "Dritte Zeile" = 3) )
get_my_options()$output
which_output()
df1 <- 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)
)
#+ 
df1 %>% Output()


df1 %>% Output(output=TRUE)

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

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)
data(tli)
## Demonstrate aov
fm1 <- aov(tlimth ~ sex + ethnicty + grade + disadvg, data = tli)
fm1.table <- xtable(fm1)

Output(fm1.table)
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" 
)
knitr::kable(
  df1, row.names = FALSE,
  format = "markdown" 
)
knitr::kable(
  df1, row.names = FALSE,
  format = "pandoc" 
)

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)
library("xtable")
print(xtable(my_data), type = "html", include.rownames=FALSE, html.table.attributes=list("border='0' cellpadding='5' "))
library(xtable)
print(xtable(my_data), type = 'html')
library(xtable)
print(xtable(my_data), type = 'html', html.table.attributes = '')
library("pander")
pandoc.table(my_data)
library("pander")
pandoc.table(my_data, split.cells = 5)
pander::panderOptions('table.split.table', 350)
pander::pandoc.table(my_data, style="rmarkdown")
library("ascii")
print(ascii(my_data), type = 'pandoc')
library("htmlTable")
htmlTable(my_data, col.rgroup = c("none", "#F7F7F7"))
library(hwriter)
hwrite(my_data, border=0)

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')
  )
)


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