Skip to content

Commit

Permalink
Minor adjustments for R CMD check
Browse files Browse the repository at this point in the history
  • Loading branch information
1beb committed Jul 14, 2020
1 parent c30b9eb commit 34e846b
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 826 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ jobs:
- uses: actions/checkout@v2
- name: Add kableExtra
run: Rscript -e 'install.packages("kableExtra")'
- name: CRAN crunch
run: Rscript -e 'install.packages("crunch")'
- name: Build
run: R CMD build --no-build-vignettes --no-manual .
- name: Check
run: |
R CMD check --no-vignettes --no-manual crunchtabs_*.tar.gz
R CMD check --no-vignettes --ignore-vignettes --no-manual crunchtabs_*.tar.gz
- name: Coverage
run: |
Rscript -e 'covr::codecov(token = "${{ secrets.CODECOV_TOKEN }}")'
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ URL: https://github.com/Crunch-io/crunchtabs
BugReports: https://github.com/Crunch-io/crunchtabs/issues
License: LGPL (>= 3)
Depends:
R (>= 3.3.0),
R (>= 3.5.0),
crunch,
kableExtra
Imports:
Expand Down
18 changes: 8 additions & 10 deletions R/codebookLatex.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ codeBookItemBody.CategoricalVariable <- function(x, ...) {
kableExtra::kable(
k, "latex", booktabs = TRUE, longtable = TRUE, align = alignment) %>%
kable_styling_defaults(...) %>%
column_spec(c(1,3), width = "1in")
kableExtra::column_spec(c(1,3), width = "1in")
}


Expand All @@ -156,9 +156,7 @@ codeBookItemBody.CategoricalArrayVariable <- function(x, ...) {
col_two <- 1.5


k <- k %>% dplyr::mutate(
Variable = cell_spec(Variable, "latex", monospace = TRUE)
)
k$Variable <- kableExtra::cell_spec(k$Variable, "latex", monospace = TRUE)

ln = ncol(k) - 2

Expand All @@ -170,10 +168,10 @@ codeBookItemBody.CategoricalArrayVariable <- function(x, ...) {
align = alignment,
escape = F) %>%
# kable_styling_defaults(...) %>%
column_spec(1, width = paste0(col_one, "in")) %>%
column_spec(2, width = paste0(col_two, "in")) %>%
kableExtra::column_spec(1, width = paste0(col_one, "in")) %>%
kableExtra::column_spec(2, width = paste0(col_two, "in")) %>%
# column_spec(c(3:ncol(k)), width = paste0(header_width[-1], "in")) %>%
add_header_above(c("", "", "Codes" = ln))
kableExtra::add_header_above(c("", "", "Codes" = ln))
}

#' @describeIn codeBookItemBody Creates item body for MultipleResponseVariable
Expand All @@ -187,7 +185,7 @@ codeBookItemBody.DatetimeVariable <- function(x, ...) {
alignment <- c("c", "l")
kableExtra::kable(k, "latex", booktabs = TRUE, longtable = TRUE, align = alignment) %>%
kable_styling_defaults(...) %>%
column_spec(1, width = "1in")
kableExtra::column_spec(1, width = "1in")
}

#' @describeIn codeBookItemBody Creates item body for NumericVariable
Expand All @@ -197,7 +195,7 @@ codeBookItemBody.NumericVariable <- function(x, ...) {
alignment <- c("c", "l")
kableExtra::kable(k, "latex", booktabs = TRUE, longtable = TRUE, align = alignment) %>%
kable_styling_defaults(...) %>%
column_spec(1, width = "1in")
kableExtra::column_spec(1, width = "1in")
}

#' @describeIn codeBookItemBody Creates item body for TextVariable
Expand All @@ -207,7 +205,7 @@ codeBookItemBody.TextVariable <- function(x, ...) {
alignment <- c("c","l")
kableExtra::kable(k, "latex", booktabs = TRUE, longtable = TRUE, align = alignment) %>%
kable_styling_defaults(...) %>%
column_spec(1, width = "1in")
kableExtra::column_spec(1, width = "1in")
}

# utils ----
Expand Down
48 changes: 30 additions & 18 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,39 @@ collapse_items <- function(x, and = FALSE, or = FALSE, quotes = FALSE){
#' crunch test wrapper
#'
#' Use this to wrap tests that require access to
#' the crunch api
#' the crunch api.
#'
#'
#' @param fixture_path A full path to fixtures
#' @param expr An expression to be run within the api fixture
#' @export
# with_api_fixture <- function(fixture_path, expr) {
# with(
# crunch::temp.options(
# crunch.api = "https://app.crunch.io/api/",
# httptest.mock.paths = fixture_path,
# crunch.show.progress = FALSE
# ),
# httptest::with_mock_api(
# # Also need to redact UUIDs as is done in POSTs
# with_mock(
# `crunch::crPOST` = function(...) {
# args <- list(...)
# # Necessary for post
# args$body <- gsub("([0-9a-f]{6})[0-9a-f]{26}", "\\1", args$body)
# args[[1]] <- gsub("([0-9a-f]{6})[0-9a-f]{26}", "\\1", args[[1]])
# #args$body <- gsub("[0-9A-Za-z]{22}([0-9]{6})", "\\1", args$body)
# #args[[1]] <- gsub("[0-9A-Za-z]{22}([0-9]{6})", "\\1", args[[1]])
# do.call(
# function(...) crunch:::crunchAPI("POST", ...),
# args
# )
# },
# expr
# )
# )
# )
# }
with_api_fixture <- function(fixture_path, expr) {
with(
crunch::temp.options(
Expand All @@ -170,27 +198,11 @@ with_api_fixture <- function(fixture_path, expr) {
crunch.show.progress = FALSE
),
httptest::with_mock_api(
# Also need to redact UUIDs as is done in POSTs
with_mock(
`crunch::crPOST` = function(...) {
args <- list(...)
# Necessary for post
args$body <- gsub("([0-9a-f]{6})[0-9a-f]{26}", "\\1", args$body)
args[[1]] <- gsub("([0-9a-f]{6})[0-9a-f]{26}", "\\1", args[[1]])
#args$body <- gsub("[0-9A-Za-z]{22}([0-9]{6})", "\\1", args$body)
#args[[1]] <- gsub("[0-9A-Za-z]{22}([0-9]{6})", "\\1", args[[1]])
do.call(
function(...) crunch:::crunchAPI("POST", ...),
args
)
},
expr
)
expr
)
)
}


#' Default Logo
#'
#' Use YouGov's default logo. All trademarks are property of their respective owners.
Expand Down
2 changes: 1 addition & 1 deletion man/with_api_fixture.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file removed tests/testthat/Example Dataset with Nets.pdf
Binary file not shown.
Loading

0 comments on commit 34e846b

Please sign in to comment.