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
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
}

0 commit comments

Comments
 (0)