-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRScript-template.R
More file actions
50 lines (44 loc) · 1.68 KB
/
RScript-template.R
File metadata and controls
50 lines (44 loc) · 1.68 KB
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
#' ---
#' title: "RScript Template"
#' author: "Your Name"
#' date: "`r format(Sys.Date())`"
#' output:
#' html_document:
#' theme: readable
#' code_download: true
#' word_document: default
#' pdf_document:
#' number_sections: true
#' ---
#+ echo=FALSE
knitr::opts_chunk$set(
warning = FALSE, # avoid warnings and messages in the output
message = FALSE, # with FALSE, they appear in the console
fig.height = 5, # set default figure size
fig.width = 6
)
#' This is a sample R script, formatted so that you can use `File -> Compile Report` or
#' `Ctrl+Shift+K` to run analyses and turn it into an HTML document, a Word document or a PDF.
#' The general rule is that everything is just R code, but comments that begin with
#' `#'` are treated as text in the output.
#'
#' * I use section headers, `#' ## Section` to break the script into sections and provide
#' other explanation.
#'
#' * All other Rmarkdown constructs apply. E.g., these lines are a bullet list.
#'
#' ## Load packages
#' Generally, I find it useful to load all packages I'm using at the beginning of a script.
library(vcdExtra) # for data and graphics
#' ## Load data
#' Illustrate the `Abortion` data. For details: `help(Abortion, package = "vcdExtra")`.
data(Abortion, package = "vcdExtra")
#' Look at what's there. The `Abortion` table has `r sum(Abortion)` observations.
str(Abortion)
#' ## Print the table nicely
#' `ftable()` flattens the table to a two-way display, with some variables assigned to the rows
#' and others assigned to the columns.
ftable(Abortion)
#' ## Make a plot
#' I want to make a fourfold plot of `Status` by `Support_Abortion` each level of `Sex`
fourfold(aperm(Abortion, 3:1))