diff --git a/.github/.gitignore b/.github/.gitignore new file mode 100644 index 00000000..2d19fc76 --- /dev/null +++ b/.github/.gitignore @@ -0,0 +1 @@ +*.html diff --git a/.github/workflows/check-standard.yaml b/.github/workflows/check-standard.yaml new file mode 100644 index 00000000..b0cd26b1 --- /dev/null +++ b/.github/workflows/check-standard.yaml @@ -0,0 +1,92 @@ +# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag. +# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions +on: + push: + branches: + - main + - master + pull_request: + branches: + - main + - master + +name: R-CMD-check + +jobs: + R-CMD-check: + runs-on: ${{ matrix.config.os }} + + name: ${{ matrix.config.os }} (${{ matrix.config.r }}) + + strategy: + fail-fast: false + matrix: + config: + - {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} + + env: + R_REMOTES_NO_ERRORS_FROM_WARNINGS: true + RSPM: ${{ matrix.config.rspm }} + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + + steps: + - uses: actions/checkout@v2 + + - uses: r-lib/actions/setup-r@v1 + with: + r-version: ${{ matrix.config.r }} + + - uses: r-lib/actions/setup-pandoc@v1 + + - name: Query dependencies + run: | + install.packages('remotes') + saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) + writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") + shell: Rscript {0} + + - name: Restore R package cache + if: runner.os != 'Windows' + uses: actions/cache@v2 + with: + path: ${{ env.R_LIBS_USER }} + key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} + restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- + + - name: Install system dependencies + if: runner.os == 'Linux' + run: | + while read -r cmd + do + eval sudo $cmd + done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))') + + - name: Install dependencies + run: | + remotes::install_deps(dependencies = TRUE) + remotes::install_cran("rcmdcheck") + shell: Rscript {0} + + - name: Install tinytex + run: | + tinytex::install_tinytex() + shell: Rscript {0} + + - name: Check + env: + _R_CHECK_CRAN_INCOMING_REMOTE_: false + run: | + options(crayon.enabled = TRUE) + 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") + shell: Rscript {0} + + - name: Coverage + run: | + Rscript -e 'covr::codecov(token = "${{ secrets.CODECOV_TOKEN }}")' + + - name: Upload check results + if: failure() + uses: actions/upload-artifact@main + with: + name: results + path: check diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index f943fd17..00000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: CI - -on: [push] - -jobs: - build: - runs-on: ubuntu-latest - container: 1beb/crunchtabs - - steps: - - uses: actions/checkout@v2 - - name: Build - run: R CMD build --no-build-vignettes --no-manual . - - name: Check - run: | - R CMD check --no-vignettes --ignore-vignettes --no-manual crunchtabs_*.tar.gz - - name: Coverage - run: | - Rscript -e 'covr::codecov(token = "${{ secrets.CODECOV_TOKEN }}")' diff --git a/.github/workflows/internal_tests.yml b/.github/workflows/internal_tests.yml deleted file mode 100644 index 058eee1f..00000000 --- a/.github/workflows/internal_tests.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: internal_tests - -on: - push: - branches: - - develop - - master - -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Repository Dispatch - run: | - curl -X POST -u "${{ secrets.PAT_USERNAME }}:${{ secrets.PAT_TOKEN }}" -H "Accept: application/vnd.github.everest-preview+json" -H "Content-Type: application/json" https://api.github.com/repos/yougov-datascience/crunchtabs_internal_tests/dispatches --data '{"event_type": "crunchtabs_hook"}' diff --git a/DESCRIPTION b/DESCRIPTION index 8af3cc26..29512216 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -6,7 +6,7 @@ Description: In order to generate custom survey reports, this package provides 'banners' (cross-tabulations) and codebooks of datasets in the Crunch () web service. Reports can be written in 'PDF' format using 'LaTeX' or in Microsoft Excel '.xlsx' files. -Version: 1.4.1 +Version: 1.4.2 Authors@R: c( person("Persephone", "Tsebelis", role="aut"), person("Kamil", "Sedrowicz", role="aut"), @@ -20,6 +20,7 @@ Depends: crunch, Imports: digest, + dplyr, httr, jsonlite, kableExtra (>= 1.1.0.9000), @@ -27,8 +28,10 @@ Imports: methods, openxlsx, rlang, + stringi, tinytex Suggests: + arrow, covr, knitr, mockery, diff --git a/NAMESPACE b/NAMESPACE index 4951e440..bb952296 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -106,7 +106,10 @@ importFrom(stats,median) importFrom(stats,pnorm) importFrom(stats,quantile) importFrom(stats,weighted.mean) +importFrom(utils,capture.output) +importFrom(utils,head) importFrom(utils,installed.packages) importFrom(utils,modifyList) importFrom(utils,stack) +importFrom(utils,tail) importFrom(utils,type.convert) diff --git a/NEWS.md b/NEWS.md index 0e4bb3e7..ce9e7d68 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,7 @@ ## crunchtabs 1.4.2 - 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. +- 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). ## crunchtabs 1.4.1 diff --git a/R/codeBookGeneric.R b/R/codeBookGeneric.R index b57275e3..e2a74334 100644 --- a/R/codeBookGeneric.R +++ b/R/codeBookGeneric.R @@ -34,6 +34,7 @@ #' @param logging Leave logs in the working directory, defaults to FALSE #' @param filename A string. The desired basename of the resulting file with no extension #' (i.e, "mycodebook") +#' @param open Should the resulting PDF be opened? Defaults to FALSE #' @param ... Additional arguments passed to \link[kableExtra]{kable_styling} Unused. #' @md #' @@ -42,7 +43,7 @@ writeCodeBookLatexGeneric <- function( table_of_contents = FALSE, sample_desc = NULL, field_period = NULL, preamble = NULL, suppress_zero_counts = FALSE, appendix = TRUE, logo = NULL, position = NULL, path = NULL, filename = NULL, - logging = FALSE, ...) { + logging = FALSE, open = FALSE, ...) { options("crunchtabs.codebook.suppress.zeros" = suppress_zero_counts) @@ -118,7 +119,7 @@ writeCodeBookLatexGeneric <- function( body <- codeBookItemBody(x, meta = meta[meta$alias == nm,], ...) # A kable if (appendix & !is.list(body)) { - if (grepl("longtabu", body)) { + if (length(capture.output(body)) > 20) { appendices[[nm]] <- list() description <- codeBookItemTxtDescriptionGeneral(x, nm, meta) @@ -266,6 +267,7 @@ writeCodeBookLatexGeneric <- function( #' @param x An R vector #' @param nm The alias of the current codeBookItem #' @param meta A specifically formatted data.frame with meta data. +#' @param ... Further arguments, not used. #' #' @export codeBookItemTxtHeaderGeneral <- function(x, nm, meta, ...) { @@ -372,3 +374,28 @@ codeBookItemTxtDescriptionGeneral <- function(x, nm, meta, ...) { tex } + +#' Get class name from arrow variable +#' +#' Arrow does not provide a method for class on it's variables. This function prints out +#' the schema and captures the appropriate output. +#' +#' @param ds An arrow dataset +#' @param variable A string identifying the variable +get_class <- function(ds, variable) { + # nocov start + r <- utils::capture.output(ds$schema[[variable]]) + r <- r[2] + r <- gsub(variable, "", r) + r <- gsub(": ", "", r) + + if (r %in% c("string")) + return("character") + if (r %in% c("int32")) + return("integer") + if (r %in% c("float", "double")) + return("numeric") + if (grepl("dictionary", r)) + return("factor") + # nocov end +} diff --git a/R/codeBookItemBody.R b/R/codeBookItemBody.R index d8cd0333..2830dacc 100644 --- a/R/codeBookItemBody.R +++ b/R/codeBookItemBody.R @@ -3,6 +3,7 @@ #' Create codebook item body. #' #' @param x A crunch dataset object +#' @param meta A data.frame containing meta data. Must be provided for non-crunch datasets. #' @param ... Further arguments, not used. #' @export codeBookItemBody <- function(x, meta = NULL, ...) { @@ -76,14 +77,25 @@ codeBookItemBody.CategoricalVariable <- function(x, meta = NULL, ...) { # nolint midrule_strip <- function(x) gsub("\\midrule", "", x, fixed = TRUE) alignment <- c("d", "l", "d", "c", "d", "l", "d") - names(k) <- curlyWrap(names(k)) + # names(k) <- curlyWrap(names(k)) # al + # kableExtra::kable( + # k, "latex", + # booktabs = TRUE, align = scolumnAlign(k, alignment), + # longtable = TRUE, linesep = "", escape = FALSE + # ) %>% + # kable_styling_defaults(full_width = TRUE, ...) %>% + # kableExtra::column_spec(c(2, 6), width = "1.75in", latex_column_spec = NULL) %>% + # kableExtra::row_spec( + # 0, + # extra_latex_after = "\\cmidrule(l){1-3}\\cmidrule(l){5-7}" # nolint + # ) %>% + # midrule_strip() + kableExtra::kable( k, "latex", - booktabs = TRUE, align = scolumnAlign(k, alignment), - longtable = TRUE, linesep = "", escape = FALSE + booktabs = TRUE, longtable = TRUE, align = scolumnAlign(k, alignment), + linesep = "", escape = FALSE ) %>% - kable_styling_defaults(full_width = TRUE, ...) %>% - kableExtra::column_spec(c(2, 6), width = "1.75in", latex_column_spec = NULL) %>% kableExtra::row_spec( 0, extra_latex_after = "\\cmidrule(l){1-3}\\cmidrule(l){5-7}" # nolint @@ -92,7 +104,8 @@ codeBookItemBody.CategoricalVariable <- function(x, meta = NULL, ...) { # nolint } else { alignment <- c("d", "l", "d") names(k) <- curlyWrap(names(k)) - kab <- kableExtra::kable( + + kab <- kableExtra::kable( k, "latex", booktabs = TRUE, longtable = TRUE, align = scolumnAlign(k, alignment), linesep = "", escape = FALSE diff --git a/R/codeBookLatex.R b/R/codeBookLatex.R index 02aad77f..7b301688 100644 --- a/R/codeBookLatex.R +++ b/R/codeBookLatex.R @@ -210,7 +210,7 @@ scolumnAlign <- function(k, alignment) { if (maxnchar > 6) { alignment[i] <- sprintf("S[table-format=%s]", maxnchar) } else { - alignment[i] <- c("J", "K", "d", "M", "N", "O")[maxnchar] + alignment[i] <- c("J", "K", "d", "M", "N", "O", "L", "M", "N")[maxnchar] } } } diff --git a/R/crunchtabs-package.R b/R/crunchtabs-package.R index 89d1e99f..1bc0122c 100644 --- a/R/crunchtabs-package.R +++ b/R/crunchtabs-package.R @@ -1,6 +1,7 @@ #' @importFrom kableExtra column_spec kable_styling #' @importFrom magrittr `%>%` #' @importFrom rlang .data +#' @importFrom utils capture.output head tail #' @keywords internal "_PACKAGE" diff --git a/R/relabel.R b/R/relabel.R index 8da1002b..43c23f60 100644 --- a/R/relabel.R +++ b/R/relabel.R @@ -7,10 +7,10 @@ #' There are two important warnings to consider: #' #' * Relabeling should always occur before applying any kind of sorting using the -#' \link{\code{sortAlias}} function to avoid situations where labels could be applied +#' \link{sortAliases} function to avoid situations where labels could be applied #' inappropriately. #' * If your results object is a tracking report or recontact it is strongly recommended that you -#' set your wave labels in the \link{\code{recontact_toplines}} or \link{\code{trackingReport}}. +#' set your wave labels in the \link{recontact_toplines} or \link{trackingReport}. #' However, if you must set it here options would be the categories and items would be the wave #' names. We cannot account for aliases with only partial data (n-1 waves), you must set the #' wave names in order. @@ -36,9 +36,9 @@ #' } #' #' @md -#' @param ct An object from \link{\code{crosstabs}}, \link{\code{recontact_report}}, -#' or \link{\code{trackingReport}} -#' @param ... One or more relabel objects. See \link{\code{relabelApply}} +#' @param ct An object from \link{crosstabs}, \link{recontact_toplines}, +#' or \link{trackingReport} +#' @param ... One or more relabel objects. See \link{relabelSet} #' @export relabel <- function(ct, ...) { message("Relabeling should always occur before sorting") @@ -68,7 +68,7 @@ relabelApply <- function(results, labs) { #' Given a results object, adjust the question description. This will display as the question #' text in crunchtabs. #' @param obj A results object for a specific alias -#' @param labs A list of labels, typically passed to \link{\code{relabel}} +#' @param labs A list of labels, typically passed to \link{relabel} relabelDescription <- function(obj, labs) { if(length(labs$description) > 0) { obj$description <- labs$description @@ -81,7 +81,7 @@ relabelDescription <- function(obj, labs) { #' Given a results object, adjust the note. This will display as the text below #' the question text in crunchtabs. #' @param obj A results object for a specific alias -#' @param labs A list of labels, typically passed to \link{\code{relabel}} +#' @param labs A list of labels, typically passed to \link{relabel} relabelNotes <- function(obj, labs) { if(length(labs$notes) > 0) { obj$notes <- labs$notes @@ -93,7 +93,7 @@ relabelNotes <- function(obj, labs) { #' Set relabels #' #' An S3 method for applying updated text values to a result object in crunchtabs -#' @param obj An inner object under the results list of a \link{\code{crosstabs}} object. +#' @param obj An inner object under the results list of a \link{crosstabs} object. #' @param labs A list including at least one of the following: description, notes, items, or options relabelSet <- function(obj, labs) { UseMethod("relabelSet", obj) @@ -104,7 +104,7 @@ relabelSet <- function(obj, labs) { #' #' Relabel a ToplineVar result object. #' @param obj A results object for a specific alias -#' @param labs A list of labels, typically passed to \link{\code{relabel}} +#' @param labs A list of labels, typically passed to \link{relabel} relabelSet.ToplineVar <- function(obj, labs) { current_options <- dimnames(obj$crosstabs$Results$`___total___`$base)[[1]] if(length(labs$options) > 0) { @@ -128,7 +128,7 @@ relabelSet.ToplineVar <- function(obj, labs) { #' #' Relabel a ToplineCategoricalArray result object. #' @param obj A results object for a specific alias -#' @param labs A list of labels, typically passed to \link{\code{relabel}} +#' @param labs A list of labels, typically passed to \link{relabel} relabelSet.ToplineCategoricalArray <- function(obj, labs) { # nolint if(length(labs$options) > 0) { @@ -180,7 +180,6 @@ setResultObj <- function(results, alias, obj) { #' #' @param results A list of results #' @param alias A character identifying the alias -#' @param obj A result object getResultObj <- function(results, alias) { stopifnot(alias %in% names(results)) results[[alias]] diff --git a/R/tabbook-additions.R b/R/tabbook-additions.R index 71b6c9f5..e4d64fad 100644 --- a/R/tabbook-additions.R +++ b/R/tabbook-additions.R @@ -261,24 +261,10 @@ resultsObject <- function(x, top = NULL, weighted, body_values, body_labels, vec #' set on a per variable basis for json export only. To do so, specify the weight #' as either a list (which will be passed to `tabBookWeightSpec()`, or a data.frame #' that mimics the structure. See [`tabBookWeightSpec()`] for more details. -#' @param output_format character export format: currently supported values are "json" -#' (default) and "xlsx". -#' @param file character local filename to write to. A default filename will be #' generated from the `multitable`'s name if one is not supplied and the #' "xlsx" format is requested. Not required for "json" format export. #' of \code{\link{filters}} defined in the dataset. -#' @param use_legacy_endpoint Logical, indicating whether to use a 'legacy' -#' endpoint for compatibility (this endpoint will be removed in the future). -#' Defaults to `FALSE`, but can be set in the function, or with the environment -#' variable `R_USE_LEGACY_TABBOOK_ENDPOINT` or R option -#' `use.legacy.tabbook.endpoint`. #' @param append_default_wt passed to [`tabBookWeightSpec()`] if `weight` is a list -#' @param ... Additional "options" passed to the tab book POST request. -#' More details can be found -#' [in the crunch API documentation]( -#' https://docs.crunch.io/endpoint-reference/endpoint-multitable.html#options) -#' or [for the legacy endpoint]( -#' https://docs.crunch.io/endpoint-reference/endpoint-tabbook.html#options) #' @return If "json" format is requested, the function returns an object of #' class `TabBookResult`, containing a list of `MultitableResult` #' objects, which themselves contain `CrunchCube`s. For single weight tabbook, diff --git a/R/writeCodeBookLatex.R b/R/writeCodeBookLatex.R index 75918147..325ca555 100644 --- a/R/writeCodeBookLatex.R +++ b/R/writeCodeBookLatex.R @@ -101,7 +101,7 @@ writeCodeBookLatex <- function( body <- codeBookItemBody(ds[[nm]], ...) # A kable if (appendix & !is.list(body)) { - if (grepl("longtabu", body)) { + if (length(capture.output(body)) > 20) { appendices[[nm]] <- list() description <- codeBookItemTxtDescription(ds[[nm]]) @@ -238,7 +238,7 @@ writeCodeBookLatex <- function( } } if(open) { - file.open(pdfname) + file.open(pdfname) # nocov } } } diff --git a/README.md b/README.md index ccc6d5c4..963f06c6 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Crunchtabs allow for the automatic generation of toplines, crosstabulation and codebooks directly from a crunch dataset. -![CI](https://github.com/Crunch-io/crunchtabs/workflows/CI/badge.svg?branch=main) [![codecov](https://codecov.io/gh/Crunch-io/crunchtabs/branch/main/graph/badge.svg)](https://codecov.io/gh/Crunch-io/crunchtabs) +![CI](https://github.com/Crunch-io/crunchtabs/workflows/R-CMD-check/badge.svg?branch=main) [![codecov](https://codecov.io/gh/Crunch-io/crunchtabs/branch/main/graph/badge.svg)](https://codecov.io/gh/Crunch-io/crunchtabs) ## Quick Start @@ -141,11 +141,3 @@ Generating a codebook is easy! # Use ds = newExampleDataset() if not found! writeCodeBookLatex(ds) - -## For developers - -The repository includes a Makefile to facilitate some common tasks. - -### Running tests - -`$ make test`. Requires the [httptest](https://github.com/nealrichardson/httptest) package. You can also specify a specific test file or files to run by adding a "file=" argument, like `$ make test file=latex`. `test_package` will do a regular-expression pattern match within the file names. See its documentation in the `testthat` package. diff --git a/inst/codebook_latex_wrap.tex b/inst/codebook_latex_wrap.tex index 799c9642..fae32c21 100644 --- a/inst/codebook_latex_wrap.tex +++ b/inst/codebook_latex_wrap.tex @@ -34,6 +34,9 @@ \newcolumntype{M}{S[table-format=4]} \newcolumntype{N}{S[table-format=5]} \newcolumntype{O}{S[table-format=6]} +\newcolumntype{L}{S[table-format=7]} +\newcolumntype{M}{S[table-format=8]} +\newcolumntype{N}{S[table-format=9]} % default is 3 so it's not included above \usepackage{float} \usepackage{marginnote} diff --git a/man/codeBookItemBody.Rd b/man/codeBookItemBody.Rd index 0a3c3eb1..abe9f125 100644 --- a/man/codeBookItemBody.Rd +++ b/man/codeBookItemBody.Rd @@ -30,6 +30,8 @@ codeBookItemBody(x, meta = NULL, ...) \arguments{ \item{x}{A crunch dataset object} +\item{meta}{A data.frame containing meta data. Must be provided for non-crunch datasets.} + \item{...}{Further arguments, not used.} } \description{ diff --git a/man/codeBookItemTxtHeaderGeneral.Rd b/man/codeBookItemTxtHeaderGeneral.Rd index 30af3059..ea3c03e1 100644 --- a/man/codeBookItemTxtHeaderGeneral.Rd +++ b/man/codeBookItemTxtHeaderGeneral.Rd @@ -12,6 +12,8 @@ codeBookItemTxtHeaderGeneral(x, nm, meta, ...) \item{nm}{The alias of the current codeBookItem} \item{meta}{A specifically formatted data.frame with meta data.} + +\item{...}{Further arguments, not used.} } \description{ Creates a text header for a codebook item diff --git a/man/getResultObj.Rd b/man/getResultObj.Rd index 13396cac..60aff43d 100644 --- a/man/getResultObj.Rd +++ b/man/getResultObj.Rd @@ -10,8 +10,6 @@ getResultObj(results, alias) \item{results}{A list of results} \item{alias}{A character identifying the alias} - -\item{obj}{A result object} } \description{ Get a result object based on alias diff --git a/man/get_class.Rd b/man/get_class.Rd new file mode 100644 index 00000000..1c445657 --- /dev/null +++ b/man/get_class.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/codeBookGeneric.R +\name{get_class} +\alias{get_class} +\title{Get class name from arrow variable} +\usage{ +get_class(ds, variable) +} +\arguments{ +\item{ds}{An arrow dataset} + +\item{variable}{A string identifying the variable} +} +\description{ +Arrow does not provide a method for class on it's variables. This function prints out +the schema and captures the appropriate output. +} diff --git a/man/relabel.Rd b/man/relabel.Rd index 6d401254..20166687 100644 --- a/man/relabel.Rd +++ b/man/relabel.Rd @@ -7,10 +7,10 @@ relabel(ct, ...) } \arguments{ -\item{ct}{An object from \link{\code{crosstabs}}, \link{\code{recontact_report}}, -or \link{\code{trackingReport}}} +\item{ct}{An object from \link{crosstabs}, \link{recontact_toplines}, +or \link{trackingReport}} -\item{...}{One or more relabel objects. See \link{\code{relabelApply}}} +\item{...}{One or more relabel objects. See \link{relabelSet}} } \description{ This function is a passthrough that allows you to relabel question items, options, question @@ -21,10 +21,10 @@ questionnaire order. As it is received by crunch, so should it be set by your re There are two important warnings to consider: \itemize{ \item Relabeling should always occur before applying any kind of sorting using the -\link{\code{sortAlias}} function to avoid situations where labels could be applied +\link{sortAliases} function to avoid situations where labels could be applied inappropriately. \item If your results object is a tracking report or recontact it is strongly recommended that you -set your wave labels in the \link{\code{recontact_toplines}} or \link{\code{trackingReport}}. +set your wave labels in the \link{recontact_toplines} or \link{trackingReport}. However, if you must set it here options would be the categories and items would be the wave names. We cannot account for aliases with only partial data (n-1 waves), you must set the wave names in order. diff --git a/man/relabelDescription.Rd b/man/relabelDescription.Rd index d0975d6f..9b23d0e3 100644 --- a/man/relabelDescription.Rd +++ b/man/relabelDescription.Rd @@ -9,7 +9,7 @@ relabelDescription(obj, labs) \arguments{ \item{obj}{A results object for a specific alias} -\item{labs}{A list of labels, typically passed to \link{\code{relabel}}} +\item{labs}{A list of labels, typically passed to \link{relabel}} } \description{ Given a results object, adjust the question description. This will display as the question diff --git a/man/relabelNotes.Rd b/man/relabelNotes.Rd index 37aedf3c..24e9dc4b 100644 --- a/man/relabelNotes.Rd +++ b/man/relabelNotes.Rd @@ -9,7 +9,7 @@ relabelNotes(obj, labs) \arguments{ \item{obj}{A results object for a specific alias} -\item{labs}{A list of labels, typically passed to \link{\code{relabel}}} +\item{labs}{A list of labels, typically passed to \link{relabel}} } \description{ Given a results object, adjust the note. This will display as the text below diff --git a/man/relabelSet.Rd b/man/relabelSet.Rd index 326eca13..a77ca5ce 100644 --- a/man/relabelSet.Rd +++ b/man/relabelSet.Rd @@ -7,7 +7,7 @@ relabelSet(obj, labs) } \arguments{ -\item{obj}{An inner object under the results list of a \link{\code{crosstabs}} object.} +\item{obj}{An inner object under the results list of a \link{crosstabs} object.} \item{labs}{A list including at least one of the following: description, notes, items, or options} } diff --git a/man/relabelSet.ToplineCategoricalArray.Rd b/man/relabelSet.ToplineCategoricalArray.Rd index b9d47479..cb93ee8f 100644 --- a/man/relabelSet.ToplineCategoricalArray.Rd +++ b/man/relabelSet.ToplineCategoricalArray.Rd @@ -9,7 +9,7 @@ \arguments{ \item{obj}{A results object for a specific alias} -\item{labs}{A list of labels, typically passed to \link{\code{relabel}}} +\item{labs}{A list of labels, typically passed to \link{relabel}} } \description{ Relabel a ToplineCategoricalArray result object. diff --git a/man/relabelSet.ToplineVar.Rd b/man/relabelSet.ToplineVar.Rd index 7ccb7d19..d32f1d16 100644 --- a/man/relabelSet.ToplineVar.Rd +++ b/man/relabelSet.ToplineVar.Rd @@ -9,7 +9,7 @@ \arguments{ \item{obj}{A results object for a specific alias} -\item{labs}{A list of labels, typically passed to \link{\code{relabel}}} +\item{labs}{A list of labels, typically passed to \link{relabel}} } \description{ Relabel a ToplineVar result object. diff --git a/man/tabBook_crunchtabs.Rd b/man/tabBook_crunchtabs.Rd index 170235d5..652791fc 100644 --- a/man/tabBook_crunchtabs.Rd +++ b/man/tabBook_crunchtabs.Rd @@ -22,30 +22,12 @@ weight variable for `dataset`, or `NULL` for unweighted results. Default is the currently applied [`weight`]. Additionally, weights can be set on a per variable basis for json export only. To do so, specify the weight as either a list (which will be passed to `tabBookWeightSpec()`, or a data.frame -that mimics the structure. See [`tabBookWeightSpec()`] for more details.} - -\item{append_default_wt}{passed to [`tabBookWeightSpec()`] if `weight` is a list} - -\item{output_format}{character export format: currently supported values are "json" -(default) and "xlsx".} - -\item{file}{character local filename to write to. A default filename will be +that mimics the structure. See [`tabBookWeightSpec()`] for more details. generated from the `multitable`'s name if one is not supplied and the "xlsx" format is requested. Not required for "json" format export. of \code{\link{filters}} defined in the dataset.} -\item{use_legacy_endpoint}{Logical, indicating whether to use a 'legacy' -endpoint for compatibility (this endpoint will be removed in the future). -Defaults to `FALSE`, but can be set in the function, or with the environment -variable `R_USE_LEGACY_TABBOOK_ENDPOINT` or R option -`use.legacy.tabbook.endpoint`.} - -\item{...}{Additional "options" passed to the tab book POST request. -More details can be found -[in the crunch API documentation]( -https://docs.crunch.io/endpoint-reference/endpoint-multitable.html#options) -or [for the legacy endpoint]( -https://docs.crunch.io/endpoint-reference/endpoint-tabbook.html#options)} +\item{append_default_wt}{passed to [`tabBookWeightSpec()`] if `weight` is a list} } \value{ If "json" format is requested, the function returns an object of diff --git a/man/trackingDeclareAvailability.Rd b/man/trackingDeclareAvailability.Rd new file mode 100644 index 00000000..43955ab8 --- /dev/null +++ b/man/trackingDeclareAvailability.Rd @@ -0,0 +1,30 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/trackingReports.R +\name{trackingDeclareAvailability} +\alias{trackingDeclareAvailability} +\title{Specify question availability in a tracking report} +\usage{ +trackingDeclareAvailability(rebuilt_results, results_available, var, labels) +} +\arguments{ +\item{rebuilt_results}{A list of result objects from crunch} + +\item{results_available}{A vector identifying in which list elements} + +\item{var}{The name of the alias that we are declaring its availability} + +\item{labels}{The wave labels} +} +\description{ +For each alias, we set an attribute that identifies it's availability +across all the datasets: "general", and "single" +\itemize{ +\item "general" means it is available in only some datasets +\item "single" means it is available in exactly one dataset +Because we use subsetting at the list level, "general" and "single" +would follow a typical path that labeling was adjusted appropriately +for presentation in the resulting pdf "single" should act as a simple +passthrough where no additional formatting or manipulation takes place +on the result. +} +} diff --git a/man/writeCodeBookLatexGeneric.Rd b/man/writeCodeBookLatexGeneric.Rd index fc02ef4c..8a7ac376 100644 --- a/man/writeCodeBookLatexGeneric.Rd +++ b/man/writeCodeBookLatexGeneric.Rd @@ -21,6 +21,7 @@ writeCodeBookLatexGeneric( path = NULL, filename = NULL, logging = FALSE, + open = FALSE, ... ) } @@ -74,6 +75,8 @@ automatically. Also accepts a path to a logo file.} \item{logging}{Leave logs in the working directory, defaults to FALSE} +\item{open}{Should the resulting PDF be opened? Defaults to FALSE} + \item{...}{Additional arguments passed to \link[kableExtra]{kable_styling} Unused.} } \description{ diff --git a/tests/testthat.R b/tests/testthat.R index 96ecdf01..86446e6d 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -1,5 +1,4 @@ library(testthat) -# library(mockery) library(crunchtabs) test_check("crunchtabs") diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R deleted file mode 100644 index 94475520..00000000 --- a/tests/testthat/setup.R +++ /dev/null @@ -1,4 +0,0 @@ -# Setup is executed when tests are run, but not when loadall is run - -source(system.file("crunch-test.R", package = "crunch")) -# Still used for with_test_authentication diff --git a/tests/testthat/teardown.R b/tests/testthat/teardown.R index b6e72008..1f90213f 100644 --- a/tests/testthat/teardown.R +++ b/tests/testthat/teardown.R @@ -1 +1 @@ -crunch_test_teardown_check() +# crunch_test_teardown_check() diff --git a/tests/testthat/test-codeBookItemBody.R b/tests/testthat/test-codeBookItemBody.R index 2a24e71e..1634d8b0 100644 --- a/tests/testthat/test-codeBookItemBody.R +++ b/tests/testthat/test-codeBookItemBody.R @@ -231,13 +231,10 @@ test_that("codeBookItemBody DatetimeVariable", { mockery::stub(codeBookItemBody.DatetimeVariable, "codeBookSummary.DatetimeVariable", smry) res <- codeBookItemBody(ds$wave) - + expect_true(grepl("\\[2014-12-01, 2015-01-01\\]", attributes(res)$kable_meta$contents[2], fixed = T)) expect_equal( - attributes(res)$kable_meta$contents, - c( - "Filled & Missing & Range", - "20 & 0 & \\[2014-12-01, 2015-01-01\\]" - ) + attributes(res)$kable_meta$contents[1], + "Filled & Missing & Range" ) expect_equal( diff --git a/tests/testthat/test-write-latex.R b/tests/testthat/test-write-latex.R index 2fedbb1d..a1073a93 100644 --- a/tests/testthat/test-write-latex.R +++ b/tests/testthat/test-write-latex.R @@ -20,6 +20,9 @@ test_that("Does not delete log/aux/out files if logging = TRUE", { system("echo 'This is a log file' >> text.log") system("echo 'This is an aux file' >> text.aux") writeLatex(cs, logging = TRUE, pdf = TRUE) + print(getwd()) + print(file.exists("text.out")) + print(readLines("text.out")) expect_true(file.exists("text.out")) expect_true(file.exists("text.log")) expect_true(file.exists("text.aux")) @@ -81,7 +84,8 @@ with_temp_dir({ writeLatex(cs, moe = 0.2, field_period = "2018-01-01 to 2018-01-02", pdf = TRUE) theme <- themeNew(default_theme = themeDefaultLatex(), digits = 1) - writeLatex(cs, theme = theme, pdf = TRUE) + mockery::stub(writeLatex, "file.open", TRUE) + writeLatex(cs, theme = theme, pdf = TRUE, open = TRUE) theme <- themeNew(default_theme = theme, font_size = 20) writeLatex(cs, theme = theme, pdf = TRUE) theme <- themeNew(default_theme = theme, diff --git a/tests/testthat/test-writeCodeBookLatex.R b/tests/testthat/test-writeCodeBookLatex.R index 5f4cb113..794a78ec 100644 --- a/tests/testthat/test-writeCodeBookLatex.R +++ b/tests/testthat/test-writeCodeBookLatex.R @@ -23,13 +23,14 @@ test_that("End to end writeCodeBookLatex", { subtitle = "Goodbye", sample_desc = "US Voting Adults", logo = "yougov", - pdf = TRUE + pdf = TRUE, + open = TRUE ) ) tex <- readLines("Example-dataset.tex") expect_equal(res, NULL) - expect_equal(length(tex), 149) + expect_equal(length(tex), 152) expect_true(file.size("Example-dataset.pdf") > 61200) # Test title expect_true( diff --git a/tests/testthat/test-writeCodeBookLatexGeneric.R b/tests/testthat/test-writeCodeBookLatexGeneric.R index c59b3968..966ac85b 100644 --- a/tests/testthat/test-writeCodeBookLatexGeneric.R +++ b/tests/testthat/test-writeCodeBookLatexGeneric.R @@ -121,7 +121,7 @@ test_that("End to end write to pdf", { ) mockery::stub(writeCodeBookLatexGeneric, "file.open", TRUE) expect_true(suppressWarnings( - writeCodeBookLatexGeneric(ds, meta, pdf = TRUE, logo = "ygblue", position = "c"))) + writeCodeBookLatexGeneric(ds, meta, pdf = TRUE, logo = "ygblue", open = TRUE, position = "c"))) expect_true(file.remove(c("General-Dataset.tex"))) expect_true(file.remove(c("General-Dataset.pdf"))) })