Skip to content

Commit

Permalink
Fix negative signs on table labels for categorical array and multiple…
Browse files Browse the repository at this point in the history
… response variables
  • Loading branch information
domjarkey committed Oct 20, 2022
1 parent 7a4028b commit 982a571
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Imports:
methods,
openxlsx,
rlang,
stringr,
tinytex
Suggests:
arrow,
Expand Down
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ S3method(tableHeader,CrossTabVar)
S3method(tableHeader,ToplineCategoricalArray)
S3method(tableHeader,ToplineVar)
S3method(tableHeader,default)
export(adjustCrunchAlias)
export(adjustCrunchDescription)
export(adjustCrunchName)
export(banner)
export(catArrayToCategoricals)
export(codeBookItemBody)
Expand Down Expand Up @@ -106,6 +109,7 @@ importFrom(stats,median)
importFrom(stats,pnorm)
importFrom(stats,quantile)
importFrom(stats,weighted.mean)
importFrom(stringr,str_extract)
importFrom(utils,capture.output)
importFrom(utils,head)
importFrom(utils,installed.packages)
Expand Down
5 changes: 3 additions & 2 deletions R/codeBookItemBody.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,15 @@ codeBookItemBody.CategoricalVariable <- function(x, meta = NULL, ...) { # nolint
}

#' @describeIn codeBookItemBody Creates item body for CategoricalArrayVariable
#' @importFrom stringr str_extract
#' @export
codeBookItemBody.CategoricalArrayVariable <- function(x, meta = NULL, ...) { # nolint
k <- codeBookSummary(x)
k[, 1] <- texEscape(k[, 1])
k[, 2] <- texEscape(k[, 2])

code_labels <- texEscape(gsub("[0-9]+ ", "", names(k))[-c(1, 2)])
code_numbers <- trimws(sub("\\D*(\\d+).*", "\\1", names(k)))[-c(1, 2)]
code_labels <- texEscape(gsub("^-?[0-9]+ ", "", names(k))[-c(1, 2)])
code_numbers <- trimws(stringr::str_extract(names(k), "^-?[0-9]*"))[-c(1, 2)]

rownames(k) <- NULL

Expand Down

0 comments on commit 982a571

Please sign in to comment.