Skip to content

Commit 7a63ed2

Browse files
committed
Updates for readme
1 parent 8994490 commit 7a63ed2

File tree

6 files changed

+52
-8
lines changed

6 files changed

+52
-8
lines changed

R/recontactQuestion.R

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#' report. If your recontact has been named using a suffix such as _pre, _post
77
#' leave that out.
88
#' @param suffixes The suffixes of recontact questions, for example _pre, _post
9-
#' @param labels Formal labels for your recontact period. For example, "Before
9+
#' @param labels Formal labels for
1010
#' the election", "After the election".
1111
#' @param weights A character vector of equal to the length of suffixes. You may
1212
#' specify a unique weight per recontact period. The default would return
@@ -62,6 +62,7 @@ recontact_toplines <- function(dataset, questions, suffixes, labels,
6262
ct$results[[question]] <- as.ToplineCategoricalArray(
6363
ct$results[[p1]],
6464
ct$results[[p2]],
65+
question,
6566
labels,
6667
weights
6768
)
@@ -81,11 +82,13 @@ recontact_toplines <- function(dataset, questions, suffixes, labels,
8182
#' distinct code to write it to latex.
8283
#'
8384
#' @param q1 The results object for the first question
84-
#' @param q2 The results onject second question
85+
#' @param q2 The results object for the second question
86+
#' @param question_alias A string specifying the resulting alias.
8587
#' @param labels Two character strings used to describe the pre and post waves
8688
#' @param weights A single alias, list, or NULL
87-
as.ToplineCategoricalArray <- function(q1, q2, labels = c("Pre", "Post"), weights) {
89+
as.ToplineCategoricalArray <- function(q1, q2, question_alias = NULL, labels = c("Pre", "Post"), weights) {
8890

91+
q1$alias <- question_alias
8992
q1$subnames <- labels
9093
q1$notes <- paste0(labels, " is weighted by ", weights, collapse = " : ")
9194
q1$type <- "categorical_array"

R/tex-table.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#' @param df An object from \link{reformatLatexResults}
77
#' @param theme A theme object from \link{themeNew}
88
#' @param alias The variable's alias
9-
latexTableBody <- function(df, theme, alias = NULL) {
9+
latexTableBody <- function(df, theme, question_alias = NULL) {
1010
# The input "df" object is shaped like this:
1111
# List of 9
1212
# $ top : NULL
@@ -157,7 +157,7 @@ latexTableBody <- function(df, theme, alias = NULL) {
157157
# Turn each table in `data` into a LaTeX table string
158158
if (topline_catarray) {
159159

160-
if (theme$latex_flip_grids | alias %in% theme$latex_flip_specific_grids) {
160+
if (theme$latex_flip_grids | question_alias %in% theme$latex_flip_specific_grids) {
161161
data$body <- as.data.frame(t(data$body), check.names = FALSE, stringsAsFactors = FALSE)
162162
}
163163
# Apparently you can't have any extra table members for these, only "body"
@@ -327,8 +327,9 @@ tableHeader.ToplineVar <- function(var, theme) {
327327
#' @export
328328
tableHeader.ToplineCategoricalArray <- function(var, theme) {
329329
header_row <- newline
330-
330+
print(var$alias)
331331
if (theme$latex_flip_grids | var$alias %in% theme$latex_flip_specific_grids) {
332+
332333
col_names <- var$subnames
333334
} else {
334335
col_names <- sapply(var$inserts_obj, name)

R/writeLatex.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ latexReportTables <- function(results, banner, theme) {
157157

158158
# PT: because this is a loop, header is singular (i.e. it's only one table at a time).
159159
header <- tableHeader(x, theme)
160-
body <- sapply(content, latexTableBody, theme = theme, alias = x$alias)
160+
body <- sapply(content, latexTableBody, theme = theme, question_alias = x$alias)
161161

162162
footer <- ifelse(
163163
x$longtable | !theme$topline,

README.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,49 @@ toplines_summary <- crosstabs(dataset = ds)
3939
writeLatex(toplines_summary, filename = "output", pdf = TRUE) # output.pdf will be written
4040
```
4141

42-
4342
![Topline Example from the Example Dataset](vignettes/example-001-topline.png)
4443

44+
### Create a recontact or pre/post Topline
45+
46+
Let's say you have a datasaet where you have asked the same question twice. Once "before" and once "after". `recontact_topline` generates a report that shows these two side by side as if they were a categorical array. Making it easier for reviewers to identify differences over time.
47+
48+
The function assumes your "before" and "after" questions are named in the same way with a suffix.
49+
50+
- q1_pre
51+
- q1_post
52+
- q3_pre
53+
- q3_post
54+
55+
```
56+
# library(crunchtabs)
57+
# login()
58+
ds <- loadDataset("Your Recontact Survey")
59+
rc <- recontact_toplines(
60+
ds,
61+
questions = c("q1", "q3"), # The base question name without suffixes
62+
suffixes = c("_pre", "_post"), # The suffixes
63+
labels = c("Pre", "Post"), # The labels associated with the pre/post
64+
weights = c("weight1", "weight2") # The weights associated with the pre/post
65+
)
66+
67+
writeLatex(rc, pdf = TRUE)
68+
```
69+
70+
![Recontact Example](vignettes/example-012-recontact-default.png)
71+
72+
Depending on your preferences you can also flip grids if have more categories than waves:
73+
74+
```
75+
theme <- themeNew(
76+
default_theme = themeDefaultLatex(),
77+
latex_flip_specific_grids = c("q1")
78+
)
79+
80+
writeLatex(rc, theme = theme, pdf = TRUE)
81+
```
82+
83+
![Recontact Example - Flipped Grid](vignettes/example-013-recontact-flipped-grid.png)
84+
4585
### Create a Cross Tabulation
4686

4787
The only additional step required for a cross tab report is to create a `banner` object. Then, setting it as the `banner` argument for the `crosstabs` function. Below, we create a cross tabulation report that shows the type of pet(s) respondents own to our survey for every question in the survey. Once you have run the code, we encourage you to open the resulting `output.pdf` file. Inside of the report you will find a cross tabulation of all questions by pet ownership.
19.6 KB
Loading
20.9 KB
Loading

0 commit comments

Comments
 (0)