Skip to content

Commit

Permalink
Finalizing changes for 1.4.0, fixed missing categories
Browse files Browse the repository at this point in the history
  • Loading branch information
1beb committed Mar 9, 2021
1 parent aeab024 commit e9dd8e2
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Description: In order to generate custom survey reports, this package provides
'banners' (cross-tabulations) of datasets in the Crunch
(<https://crunch.io/>) web service. Reports can be written in 'PDF' format
using 'LaTeX' or in Microsoft Excel '.xlsx' files.
Version: 1.3.1
Version: 1.4.0
Authors@R: c(
person("Persephone", "Tsebelis", role="aut"),
person("Kamil", "Sedrowicz", role="aut"),
Expand Down
22 changes: 22 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
## crunchtabs 1.4.0

Features:

- Relabeling for items, options, descriptions and notes via relabel #247. Allows for arbitrary question text adjustment #138 #55
- Tracking reports #232
- Recontact reports #232
- Now get a warning when you attempt to make a codebook from a weighted dataset #226
- Major updates to vignettes for tracking/recontacts #218
- Option to show only the first appearance of an alias in a tracking report as a single categorical #241
- Added ability to generate a codebook from a generic dataset using generated metadata #227
- Added ability to generate codebooks from large arrow datasets #227
- Automatically align variables, by adding "-" where category has no responses #245, #243

Fixes:

- Fix for absolutelynopagebreak duplication on wrapping tex that is a character vector instead of simple string #246
- Fix bogus warnings for format_label_column_exceptions #245
- Fix missing images from vignettes #242
- Added linting #228
- Removing legacy features from the repository #225

## crunchtabs 1.3.1

- Allows variable pass through in tracking reports such that questions that appear in one or more waves (but less than all waves) are displayed appropriately and in the order specified.
Expand Down
38 changes: 35 additions & 3 deletions R/asToplineCategoricalArray.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,41 @@ as.ToplineCategoricalArray <- function(
)
}

categoryFill <- function(clist) {
cbindFill <- function(x, y) {
r <- merge(x, y, by = "row.names", all = TRUE, sort = FALSE)
rownames(r) <- r$Row.names
r$Row.names <- NULL
r
}

addPos <- function(x) {
x[,1] <- 1:nrow(x)
x
}

r <- lapply(clist, addPos)
r <- do.call(rbind, r)
r <- data.frame(nm = names(r[,1]), pos = r[,1])
r <- unique(r)
rownames(r) <- r$nm
r$nm <- NULL

m <- Reduce(function(x,y) suppressWarnings(cbindFill(x,y)), clist)
m <- suppressWarnings(merge(m, r, by = "row.names", all = TRUE, sort = FALSE))
m <- m[with(m, order(pos)),]

rownames(m) <- m$Row.names
m$Row.names <- NULL
m$pos <- NULL
as.matrix(m)
}

counts <- obj$crosstabs$Results$`___total___`$counts
second_label <- attr(counts, "dimnames")[[1]]

obj$subnames <- labels
obj$rownames <- attr(counts, "dimnames")[[1]]

obj$notes <- questions[[1]]$notes
obj$type <- "categorical_array"
obj$labels <- labels
Expand All @@ -44,18 +74,20 @@ as.ToplineCategoricalArray <- function(
# We pull out counts per result item in wide format
count_list <- lapply(questions, function(x) x$crosstabs$Results$`___total___`$counts)
prop_list <- lapply(questions, function(x) x$crosstabs$Results$`___total___`$proportions)
m <- Reduce(function(x,y) cbind(x,y[match(rownames(x), rownames(y))]), count_list)
m <- categoryFill(count_list)

dimnames(m)[[2]] <- as.character(labels)

obj$crosstabs$Results$`___total___`$counts <- m

# We pull out proportions per result item in wide format
m <- Reduce(function(x,y) cbind(x,y[match(rownames(x), rownames(y))]), prop_list)
m <- categoryFill(prop_list)

dimnames(m)[[2]] <- as.character(labels)
obj$crosstabs$Results$`___total___`$proportions <- m

obj$rownames <- rownames(m)

class(obj) <- c("ToplineCategoricalArray", "ToplineVar", "CrossTabVar")

obj
Expand Down
2 changes: 2 additions & 0 deletions R/tex-table.R
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ tableHeader.ToplineCategoricalArray <- function(var, theme) { # nolint
if (length(col_names) == 0) {
col_names <- var$rownames
}
if (length(var$rownames) > length(col_names))
col_names <- var$rownames
}

col_names_len <- length(col_names)
Expand Down

0 comments on commit e9dd8e2

Please sign in to comment.