diff --git a/R/quarter_range.R b/R/quarter_range.R index fee3142..6498e8a 100644 --- a/R/quarter_range.R +++ b/R/quarter_range.R @@ -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) } diff --git a/inst/templates/report_v3.Rnw b/inst/templates/report_v3.Rnw index 87674e3..7c41eb0 100644 --- a/inst/templates/report_v3.Rnw +++ b/inst/templates/report_v3.Rnw @@ -4,8 +4,8 @@ \usepackage{helvet} \usepackage{geometry} \usepackage{wrapfig} -\usepackage{caption} -\usepackage{subcaption} +% \usepackage{caption} +% \usepackage{subcaption} \usepackage{tcolorbox} \tcbuselibrary{listings,breakable} @@ -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} @@ -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 @@ -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 @@ -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 @@ -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 @ @@ -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 @ diff --git a/tests/testthat/test_quarter_ranges.R b/tests/testthat/test_quarter_ranges.R new file mode 100644 index 0000000..010feda --- /dev/null +++ b/tests/testthat/test_quarter_ranges.R @@ -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')) +})