Skip to content

Commit ee53e0b

Browse files
authored
Merge pull request #259 from Crunch-io/siunitx
Siunitx
2 parents 8a3a0bf + 1f4e48f commit ee53e0b

36 files changed

+246
-128
lines changed

.github/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.html

.github/workflows/check-standard.yaml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag.
2+
# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
pull_request:
9+
branches:
10+
- main
11+
- master
12+
13+
name: R-CMD-check
14+
15+
jobs:
16+
R-CMD-check:
17+
runs-on: ${{ matrix.config.os }}
18+
19+
name: ${{ matrix.config.os }} (${{ matrix.config.r }})
20+
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
config:
25+
- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
26+
27+
env:
28+
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
29+
RSPM: ${{ matrix.config.rspm }}
30+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
31+
32+
steps:
33+
- uses: actions/checkout@v2
34+
35+
- uses: r-lib/actions/setup-r@v1
36+
with:
37+
r-version: ${{ matrix.config.r }}
38+
39+
- uses: r-lib/actions/setup-pandoc@v1
40+
41+
- name: Query dependencies
42+
run: |
43+
install.packages('remotes')
44+
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
45+
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
46+
shell: Rscript {0}
47+
48+
- name: Restore R package cache
49+
if: runner.os != 'Windows'
50+
uses: actions/cache@v2
51+
with:
52+
path: ${{ env.R_LIBS_USER }}
53+
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
54+
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-
55+
56+
- name: Install system dependencies
57+
if: runner.os == 'Linux'
58+
run: |
59+
while read -r cmd
60+
do
61+
eval sudo $cmd
62+
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')
63+
64+
- name: Install dependencies
65+
run: |
66+
remotes::install_deps(dependencies = TRUE)
67+
remotes::install_cran("rcmdcheck")
68+
shell: Rscript {0}
69+
70+
- name: Install tinytex
71+
run: |
72+
tinytex::install_tinytex()
73+
shell: Rscript {0}
74+
75+
- name: Check
76+
env:
77+
_R_CHECK_CRAN_INCOMING_REMOTE_: false
78+
run: |
79+
options(crayon.enabled = TRUE)
80+
rcmdcheck::rcmdcheck(args = c("--no-manual", "--no-build-vignettes", "--no-tests"), build_args = c("--no-build-vignettes", "--ignore-vignettes", "--no-manual"), error_on = "error", check_dir = "check")
81+
shell: Rscript {0}
82+
83+
- name: Coverage
84+
run: |
85+
Rscript -e 'covr::codecov(token = "${{ secrets.CODECOV_TOKEN }}")'
86+
87+
- name: Upload check results
88+
if: failure()
89+
uses: actions/upload-artifact@main
90+
with:
91+
name: results
92+
path: check

.github/workflows/ci.yml

Lines changed: 0 additions & 19 deletions
This file was deleted.

.github/workflows/internal_tests.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

DESCRIPTION

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Description: In order to generate custom survey reports, this package provides
66
'banners' (cross-tabulations) and codebooks of datasets in the Crunch
77
(<https://crunch.io/>) web service. Reports can be written in 'PDF' format
88
using 'LaTeX' or in Microsoft Excel '.xlsx' files.
9-
Version: 1.4.1
9+
Version: 1.4.2
1010
Authors@R: c(
1111
person("Persephone", "Tsebelis", role="aut"),
1212
person("Kamil", "Sedrowicz", role="aut"),
@@ -20,15 +20,18 @@ Depends:
2020
crunch,
2121
Imports:
2222
digest,
23+
dplyr,
2324
httr,
2425
jsonlite,
2526
kableExtra (>= 1.1.0.9000),
2627
magrittr,
2728
methods,
2829
openxlsx,
2930
rlang,
31+
stringi,
3032
tinytex
3133
Suggests:
34+
arrow,
3235
covr,
3336
knitr,
3437
mockery,

NAMESPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ importFrom(stats,median)
106106
importFrom(stats,pnorm)
107107
importFrom(stats,quantile)
108108
importFrom(stats,weighted.mean)
109+
importFrom(utils,capture.output)
110+
importFrom(utils,head)
109111
importFrom(utils,installed.packages)
110112
importFrom(utils,modifyList)
111113
importFrom(utils,stack)
114+
importFrom(utils,tail)
112115
importFrom(utils,type.convert)

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## crunchtabs 1.4.2
22

33
- INNOV-326 writeCodeBookLatex should not open by default. Add function argument open = FALSE. This avoids a situation in non-interactive sessions where the process would otherwise be stuck as it attempts to open a GTK program from a bash session.
4+
- Small change in how appendices are automatically identified. Previous iterations prepared long tables with the longtabu package. However, this tex package overwrote numeric presentation options from siunitx. This has been changed to longtable, which respects siunitx. Now appendix long tables are identified by the length of lines in their tex (20 or more).
45

56
## crunchtabs 1.4.1
67

R/codeBookGeneric.R

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#' @param logging Leave logs in the working directory, defaults to FALSE
3535
#' @param filename A string. The desired basename of the resulting file with no extension
3636
#' (i.e, "mycodebook")
37+
#' @param open Should the resulting PDF be opened? Defaults to FALSE
3738
#' @param ... Additional arguments passed to \link[kableExtra]{kable_styling} Unused.
3839
#' @md
3940
#'
@@ -42,7 +43,7 @@ writeCodeBookLatexGeneric <- function(
4243
table_of_contents = FALSE, sample_desc = NULL, field_period = NULL,
4344
preamble = NULL, suppress_zero_counts = FALSE, appendix = TRUE,
4445
logo = NULL, position = NULL, path = NULL, filename = NULL,
45-
logging = FALSE, ...) {
46+
logging = FALSE, open = FALSE, ...) {
4647

4748
options("crunchtabs.codebook.suppress.zeros" = suppress_zero_counts)
4849

@@ -118,7 +119,7 @@ writeCodeBookLatexGeneric <- function(
118119
body <- codeBookItemBody(x, meta = meta[meta$alias == nm,], ...) # A kable
119120

120121
if (appendix & !is.list(body)) {
121-
if (grepl("longtabu", body)) {
122+
if (length(capture.output(body)) > 20) {
122123
appendices[[nm]] <- list()
123124

124125
description <- codeBookItemTxtDescriptionGeneral(x, nm, meta)
@@ -266,6 +267,7 @@ writeCodeBookLatexGeneric <- function(
266267
#' @param x An R vector
267268
#' @param nm The alias of the current codeBookItem
268269
#' @param meta A specifically formatted data.frame with meta data.
270+
#' @param ... Further arguments, not used.
269271
#'
270272
#' @export
271273
codeBookItemTxtHeaderGeneral <- function(x, nm, meta, ...) {
@@ -372,3 +374,28 @@ codeBookItemTxtDescriptionGeneral <- function(x, nm, meta, ...) {
372374

373375
tex
374376
}
377+
378+
#' Get class name from arrow variable
379+
#'
380+
#' Arrow does not provide a method for class on it's variables. This function prints out
381+
#' the schema and captures the appropriate output.
382+
#'
383+
#' @param ds An arrow dataset
384+
#' @param variable A string identifying the variable
385+
get_class <- function(ds, variable) {
386+
# nocov start
387+
r <- utils::capture.output(ds$schema[[variable]])
388+
r <- r[2]
389+
r <- gsub(variable, "", r)
390+
r <- gsub(": ", "", r)
391+
392+
if (r %in% c("string"))
393+
return("character")
394+
if (r %in% c("int32"))
395+
return("integer")
396+
if (r %in% c("float", "double"))
397+
return("numeric")
398+
if (grepl("dictionary", r))
399+
return("factor")
400+
# nocov end
401+
}

R/codeBookItemBody.R

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#' Create codebook item body.
44
#'
55
#' @param x A crunch dataset object
6+
#' @param meta A data.frame containing meta data. Must be provided for non-crunch datasets.
67
#' @param ... Further arguments, not used.
78
#' @export
89
codeBookItemBody <- function(x, meta = NULL, ...) {
@@ -76,14 +77,25 @@ codeBookItemBody.CategoricalVariable <- function(x, meta = NULL, ...) { # nolint
7677
midrule_strip <- function(x) gsub("\\midrule", "", x, fixed = TRUE)
7778

7879
alignment <- c("d", "l", "d", "c", "d", "l", "d")
79-
names(k) <- curlyWrap(names(k))
80+
# names(k) <- curlyWrap(names(k)) # al
81+
# kableExtra::kable(
82+
# k, "latex",
83+
# booktabs = TRUE, align = scolumnAlign(k, alignment),
84+
# longtable = TRUE, linesep = "", escape = FALSE
85+
# ) %>%
86+
# kable_styling_defaults(full_width = TRUE, ...) %>%
87+
# kableExtra::column_spec(c(2, 6), width = "1.75in", latex_column_spec = NULL) %>%
88+
# kableExtra::row_spec(
89+
# 0,
90+
# extra_latex_after = "\\cmidrule(l){1-3}\\cmidrule(l){5-7}" # nolint
91+
# ) %>%
92+
# midrule_strip()
93+
8094
kableExtra::kable(
8195
k, "latex",
82-
booktabs = TRUE, align = scolumnAlign(k, alignment),
83-
longtable = TRUE, linesep = "", escape = FALSE
96+
booktabs = TRUE, longtable = TRUE, align = scolumnAlign(k, alignment),
97+
linesep = "", escape = FALSE
8498
) %>%
85-
kable_styling_defaults(full_width = TRUE, ...) %>%
86-
kableExtra::column_spec(c(2, 6), width = "1.75in", latex_column_spec = NULL) %>%
8799
kableExtra::row_spec(
88100
0,
89101
extra_latex_after = "\\cmidrule(l){1-3}\\cmidrule(l){5-7}" # nolint
@@ -92,7 +104,8 @@ codeBookItemBody.CategoricalVariable <- function(x, meta = NULL, ...) { # nolint
92104
} else {
93105
alignment <- c("d", "l", "d")
94106
names(k) <- curlyWrap(names(k))
95-
kab <- kableExtra::kable(
107+
108+
kab <- kableExtra::kable(
96109
k, "latex",
97110
booktabs = TRUE, longtable = TRUE, align = scolumnAlign(k, alignment),
98111
linesep = "", escape = FALSE

R/codeBookLatex.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ scolumnAlign <- function(k, alignment) {
210210
if (maxnchar > 6) {
211211
alignment[i] <- sprintf("S[table-format=%s]", maxnchar)
212212
} else {
213-
alignment[i] <- c("J", "K", "d", "M", "N", "O")[maxnchar]
213+
alignment[i] <- c("J", "K", "d", "M", "N", "O", "L", "M", "N")[maxnchar]
214214
}
215215
}
216216
}

R/crunchtabs-package.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#' @importFrom kableExtra column_spec kable_styling
22
#' @importFrom magrittr `%>%`
33
#' @importFrom rlang .data
4+
#' @importFrom utils capture.output head tail
45
#' @keywords internal
56
"_PACKAGE"
67

R/relabel.R

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
#' There are two important warnings to consider:
88
#'
99
#' * Relabeling should always occur before applying any kind of sorting using the
10-
#' \link{\code{sortAlias}} function to avoid situations where labels could be applied
10+
#' \link{sortAliases} function to avoid situations where labels could be applied
1111
#' inappropriately.
1212
#' * If your results object is a tracking report or recontact it is strongly recommended that you
13-
#' set your wave labels in the \link{\code{recontact_toplines}} or \link{\code{trackingReport}}.
13+
#' set your wave labels in the \link{recontact_toplines} or \link{trackingReport}.
1414
#' However, if you must set it here options would be the categories and items would be the wave
1515
#' names. We cannot account for aliases with only partial data (n-1 waves), you must set the
1616
#' wave names in order.
@@ -36,9 +36,9 @@
3636
#' }
3737
#'
3838
#' @md
39-
#' @param ct An object from \link{\code{crosstabs}}, \link{\code{recontact_report}},
40-
#' or \link{\code{trackingReport}}
41-
#' @param ... One or more relabel objects. See \link{\code{relabelApply}}
39+
#' @param ct An object from \link{crosstabs}, \link{recontact_toplines},
40+
#' or \link{trackingReport}
41+
#' @param ... One or more relabel objects. See \link{relabelSet}
4242
#' @export
4343
relabel <- function(ct, ...) {
4444
message("Relabeling should always occur before sorting")
@@ -68,7 +68,7 @@ relabelApply <- function(results, labs) {
6868
#' Given a results object, adjust the question description. This will display as the question
6969
#' text in crunchtabs.
7070
#' @param obj A results object for a specific alias
71-
#' @param labs A list of labels, typically passed to \link{\code{relabel}}
71+
#' @param labs A list of labels, typically passed to \link{relabel}
7272
relabelDescription <- function(obj, labs) {
7373
if(length(labs$description) > 0) {
7474
obj$description <- labs$description
@@ -81,7 +81,7 @@ relabelDescription <- function(obj, labs) {
8181
#' Given a results object, adjust the note. This will display as the text below
8282
#' the question text in crunchtabs.
8383
#' @param obj A results object for a specific alias
84-
#' @param labs A list of labels, typically passed to \link{\code{relabel}}
84+
#' @param labs A list of labels, typically passed to \link{relabel}
8585
relabelNotes <- function(obj, labs) {
8686
if(length(labs$notes) > 0) {
8787
obj$notes <- labs$notes
@@ -93,7 +93,7 @@ relabelNotes <- function(obj, labs) {
9393
#' Set relabels
9494
#'
9595
#' An S3 method for applying updated text values to a result object in crunchtabs
96-
#' @param obj An inner object under the results list of a \link{\code{crosstabs}} object.
96+
#' @param obj An inner object under the results list of a \link{crosstabs} object.
9797
#' @param labs A list including at least one of the following: description, notes, items, or options
9898
relabelSet <- function(obj, labs) {
9999
UseMethod("relabelSet", obj)
@@ -104,7 +104,7 @@ relabelSet <- function(obj, labs) {
104104
#'
105105
#' Relabel a ToplineVar result object.
106106
#' @param obj A results object for a specific alias
107-
#' @param labs A list of labels, typically passed to \link{\code{relabel}}
107+
#' @param labs A list of labels, typically passed to \link{relabel}
108108
relabelSet.ToplineVar <- function(obj, labs) {
109109
current_options <- dimnames(obj$crosstabs$Results$`___total___`$base)[[1]]
110110
if(length(labs$options) > 0) {
@@ -128,7 +128,7 @@ relabelSet.ToplineVar <- function(obj, labs) {
128128
#'
129129
#' Relabel a ToplineCategoricalArray result object.
130130
#' @param obj A results object for a specific alias
131-
#' @param labs A list of labels, typically passed to \link{\code{relabel}}
131+
#' @param labs A list of labels, typically passed to \link{relabel}
132132
relabelSet.ToplineCategoricalArray <- function(obj, labs) { # nolint
133133

134134
if(length(labs$options) > 0) {
@@ -180,7 +180,6 @@ setResultObj <- function(results, alias, obj) {
180180
#'
181181
#' @param results A list of results
182182
#' @param alias A character identifying the alias
183-
#' @param obj A result object
184183
getResultObj <- function(results, alias) {
185184
stopifnot(alias %in% names(results))
186185
results[[alias]]

0 commit comments

Comments
 (0)