Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions R/quarter_range.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ quarter_begin <- function(year, quarter){
#' @importFrom lubridate make_date
quarter_end <- function(year, quarter){
month <- (4 + 3*(quarter-1)) %% 12
if(quarter == 4){
year <- year + 1
}
make_date(year, month, 01)
}

Expand Down
32 changes: 17 additions & 15 deletions inst/templates/report_v3.Rnw
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
\usepackage{helvet}
\usepackage{geometry}
\usepackage{wrapfig}
\usepackage{caption}
\usepackage{subcaption}
% \usepackage{caption}
% \usepackage{subcaption}
\usepackage{tcolorbox}
\tcbuselibrary{listings,breakable}

Expand Down Expand Up @@ -40,7 +40,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Redefine subfloat as per knitr instructions for using subcaption
\newcommand{\subfloat}[2][need a sub-caption]{\subcaptionbox{#1}{#2}}
%\newcommand{\subfloat}[2][need a sub-caption]{\subcaptionbox{#1}{#2}}

% Only if the base font of the document is to be sans serif
\renewcommand*\familydefault{\sfdefault}
Expand Down Expand Up @@ -155,8 +155,8 @@ if(include_cid){ cat('\\includeCIDtrue') }else{ cat('\\includeCIDfalse') }

\begin{minipage}[t][0.26\textheight][t]{0.5\textwidth}
\strut\vspace*{-\baselineskip}\newline
\captionsetup{margin=.5cm}
\setlength{\abovecaptionskip}{-10pt plus 3pt minus 2pt}
% \captionsetup{margin=.5cm}
% \setlength{\abovecaptionskip}{-10pt plus 3pt minus 2pt}
\ifincludeCID
\parbox{\textwidth}{ {\tiny \Sexpr{info540727}} \par }
\fi
Expand Down Expand Up @@ -201,13 +201,15 @@ if(include_cid){ cat('\\includeCIDtrue') }else{ cat('\\includeCIDfalse') }
\parbox{\textwidth}{\centering Documented Contraceptive Preference}
\centering{
<< p1-bot-left, include=TRUE, message=FALSE, echo=FALSE>>=
# DON"T INCLUDE A CAPTION. It will bork the environment
knitr::kable(tbl82C4A3, format.args = list(digits=3), align='c',
booktabs=T, format="latex") %>%
kable_styling(font_size = 14) %>%
row_spec(0, bold=T) %>%
footnote(symbol="\\\\small Other includes Depo, pills, and condoms",
escape=F)
# DON"T INCLUDE A CAPTION. It will bork the environment
# WIP: Kable styling causing LaTeX error: FLOAT LOSS.
# Adds \table around \tabular in generated .tex
knitr::kable(tbl82C4A3, format.args = list(digits=3), align='c',
booktabs=T, format="latex") %>%
# kable_styling(font_size = 14) %>%
row_spec(0, bold=T) %>%
footnote(symbol="\\\\small Other includes Depo, pills, and condoms",
escape=F)
@
}
\vfill
Expand Down Expand Up @@ -248,7 +250,7 @@ if(include_cid){ cat('\\includeCIDtrue') }else{ cat('\\includeCIDfalse') }
\parbox{\textwidth}{ {\tiny \Sexpr{infoBDBC81}} \par }
\fi
\centering
Women Who had a Live Birth and Received Their Preferred Contraceptive\\
Women Who had a Live Birth and Wanted Contraception that Received Their Preferred Method\\
\vspace{2mm}
<< p2-top-left, include=TRUE, fig.show='hold', fig.width=2.5, fig.height=2.5, dev='pdf' >>=
figBDBC81
Expand Down Expand Up @@ -289,7 +291,7 @@ if(include_cid){ cat('\\includeCIDtrue') }else{ cat('\\includeCIDfalse') }
\parbox{\textwidth}{ {\tiny \Sexpr{infoADA835A}} \par }
\fi
\centering
Overall Rate\\
Overall Rate (Tubal, IUD, and Nexplanon)\\
<< p2-mid-left, include=TRUE, fig.show='hold', fig.width=2.5, fig.height=2.5, dev='pdf' >>=
figADA835A
@
Expand Down Expand Up @@ -366,7 +368,7 @@ if(include_cid){ cat('\\includeCIDtrue') }else{ cat('\\includeCIDfalse') }
\parbox{\textwidth}{ {\tiny \Sexpr{info0DB9AF}} \par }
\fi
\centering
Overall Rate\\
Overall Rate (Tubal, IUD, and Nexplanon)\\
<< p3-mid-left, include=TRUE, fig.show='hold', fig.width=2.5, fig.height=2.5, dev='pdf' >>=
fig0DB9AF
@
Expand Down
23 changes: 23 additions & 0 deletions tests/testthat/test_quarter_ranges.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
test_that("end ranges calculate as expected", {
QEnd1 <- quarter_end(2000, 1)
QEnd2 <- quarter_end(2000, 2)
QEnd3 <- quarter_end(2000, 3)
QEnd4 <- quarter_end(2000, 4)

expect_equal(QEnd1, lubridate::ymd('2000-04-01'))
expect_equal(QEnd2, lubridate::ymd('2000-07-01'))
expect_equal(QEnd3, lubridate::ymd('2000-10-01'))
expect_equal(QEnd4, lubridate::ymd('2001-01-01'))
})

test_that("begin ranges calculate as expected", {
QB1 <- quarter_begin(2000, 1)
QB2 <- quarter_begin(2000, 2)
QB3 <- quarter_begin(2000, 3)
QB4 <- quarter_begin(2000, 4)

expect_equal(QB1, lubridate::ymd('2000-01-01'))
expect_equal(QB2, lubridate::ymd('2000-04-01'))
expect_equal(QB3, lubridate::ymd('2000-07-01'))
expect_equal(QB4, lubridate::ymd('2000-10-01'))
})