diff --git a/DESCRIPTION b/DESCRIPTION index 656679c5..7fdfdf25 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -10,8 +10,8 @@ Description: A set of tools for writing documents The package includes additional functions for institutional color palettes, an institutional 'ggplot' theme, a function for counting manuscript words, and a bibliographical analysis toolkit. -Date: 2022-05-12 -Version: 0.9.3 +Date: 2022-09-20 +Version: 0.9.4 Authors@R: c(person(given = "James", family = "Hollway", @@ -20,9 +20,13 @@ Authors@R: comment = c(ORCID = "0000-0002-8361-9647")), person(given = "Bernhard", family = "Bieri", - role = c("ctb"), + role = "ctb", email = "bernhard.bieri@graduateinstitute.ch", - comment = c(ORCID = "0000-0001-5943-9059")) + comment = c(ORCID = "0000-0001-5943-9059")), + person(given = "Henrique", + family = "Sposito", + role = "ctb", + comment = c(ORCID = "0000-0003-3420-6085")) ) URL: https://github.com/jhollway/iheiddown BugReports: https://github.com/jhollway/iheiddown/issues @@ -51,7 +55,7 @@ Imports: Encoding: UTF-8 LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.1.2 +RoxygenNote: 7.2.0 Suggests: testthat, kableExtra, diff --git a/NEWS.md b/NEWS.md index 9bd0c964..48f93c84 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,14 @@ +# iheiddown 0.9.4 + +## Package updates: + +- Closed #126 by adding more informative message for when `percent_female()` reaches API rate limits +- Skipped `bibstats` functions tests on linux + +## Thesis + +- Added packages to 'thesis_pdf' template to improve rendering + # iheiddown 0.9.3 ## Package updates: @@ -51,7 +62,7 @@ presentation template # iheiddown 0.8.6 -# Minor fix +## Minor fix - Re-rendered README.md manually following CRAN comments about a potentially invalid URL diff --git a/R/bibfix.R b/R/bibfix.R index 420070e0..a8e2420c 100644 --- a/R/bibfix.R +++ b/R/bibfix.R @@ -23,7 +23,6 @@ # bib2df::df2bib(bib, bib_file) # } - get_used_bib <- function(bib_file, rmd_file) { if (missing(bib_file)) bib_file <- find_bib() if (missing(rmd_file)) rmd_file <- rstudioapi::getSourceEditorContext()$path diff --git a/R/bibstats.R b/R/bibstats.R index 8e160136..f638b038 100644 --- a/R/bibstats.R +++ b/R/bibstats.R @@ -28,7 +28,6 @@ #' @importFrom bib2df bib2df #' @importFrom utils install.packages #' @return Prints a summary statistic (e.g. mean or proportion) -#' NULL #' @rdname bibstats @@ -40,20 +39,19 @@ percent_female <- function(bib_file, if (missing(bib_file)) bib_file <- find_bib() if (missing(rmd_file)) rmd_file <- rstudioapi::getSourceEditorContext()$path by <- match.arg(by, c("author", "publication")) - # if (!requireNamespace("genderdata", quietly = TRUE)) { # if (!requireNamespace("remotes", quietly = TRUE)) { # utils::install.packages("remotes") # } # remotes::install_github("lmullen/genderdata") # } - bib <- suppressWarnings(bib2df::bib2df(bib_file)) if (!missing(rmd_file)) { used <- get_used_bib(bib_file, rmd_file) bib <- dplyr::filter(bib, .data$BIBTEXKEY %in% used) } authors <- bib$AUTHOR + gender <- NULL # Total percentage of women if (by == "author") { authors <- unlist(authors) @@ -61,9 +59,16 @@ percent_female <- function(bib_file, authors <- stringr::str_remove(authors, "\\}") authors <- stringr::str_remove(authors, ".*,[:blank:]") authors <- stringr::str_remove(authors, "\\s.*") - gender <- table(gender::gender(authors, method = "genderize")$gender) - paste0((1 - round(gender[2] / sum(gender), 2)) * 100, - "% female authors") + gender <- tryCatch({ + table(gender::gender(authors, method = "genderize")$gender) + }, + message = "Rate limit for the `{gender}` R package has been reached due to the amount of download requests. + Please wait a few hours and try again later." + ) + if (!is.null(gender)) { + paste0((1 - round(gender[2] / sum(gender), 2)) * 100, + "% female authors") + } } else if (by == "publication") { # Percentage of papers written by at least one women for (i in seq_len(length(authors))) { @@ -76,10 +81,17 @@ percent_female <- function(bib_file, ".*,[:blank:]") } } - gender <- sapply(authors, - function(x) any(gender::gender(x, method = "genderize")$gender == "female")) - paste0(round(sum(gender) / length(gender), 2) * 100, - "% female authors") + gender <- tryCatch({ + sapply(authors, function(x) + any(gender::gender(x, method = "genderize")$gender == "female")) + }, + message = "Rate limit for the `{gender}` R package has been reached due to the amount of download requests. + Please wait a few hours and try again later." + ) + if (!is.null(gender)) { + paste0(round(sum(gender) / length(gender), 2) * 100, + "% female authors") + } } } diff --git a/R/poster_html.R b/R/poster_html.R index 9fcf9415..4df55c0e 100644 --- a/R/poster_html.R +++ b/R/poster_html.R @@ -4,8 +4,11 @@ #' templates with a little IHEID twist to them. All exports are in HTML format. #' You can save them by printing them to PDF via a modern browser. #' -#' @inheritParams pagedown::poster_relaxed #' @param ... Additional arguments to `rmarkdown::html_document` +#' @param template Additional argument passed to `pagedown::poster_relaxed`. +#' IHEID poster templates by default. +#' @param css Additional argument passed to `pagedown::poster_relaxed`. +#' NULL by default. #' @source [`{Posterdown}`](https://github.com/brentthorne/posterdown) #' @return R Markdown output format to pass to #' [rmarkdown::render()] @@ -15,7 +18,10 @@ #' file <- file.path(tempdir(),"foo.rmd") #' rmarkdown::draft(file, template="iheiddown_poster", package="iheiddown") #' } -#' @rdname posterdown_html +#' @name posterdown_html +NULL + +#' @rdname posterdown_html #' @export iheiddown_poster <- function(..., template = system.file("rmarkdown", diff --git a/R/theme.R b/R/theme.R index c6faee4b..f0f5af68 100644 --- a/R/theme.R +++ b/R/theme.R @@ -213,4 +213,4 @@ theme_iheid <- function(base_family="sans", base_size = 11.5, color = iheid_palette("IHEID")["IHEIDGrey"])) ret <- ret + theme(plot.margin = plot_margin) ret - } +} diff --git a/cran-comments.md b/cran-comments.md index afb96346..9a9f7ec2 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -9,5 +9,4 @@ 0 errors | 0 warnings | 0 notes -- Fixed issue relating to tests on Linux - \ No newline at end of file +- Added informative message for when rate limits are reached with `percent_female()` diff --git a/inst/rmarkdown/templates/thesis_pdf/resources/template.tex b/inst/rmarkdown/templates/thesis_pdf/resources/template.tex index e67fd8e6..a5fbd020 100644 --- a/inst/rmarkdown/templates/thesis_pdf/resources/template.tex +++ b/inst/rmarkdown/templates/thesis_pdf/resources/template.tex @@ -30,6 +30,8 @@ \fancypagestyle{plain}{\fancyhf{}\fancyfoot[C]{\emph{\thepage}}} +\fancyfoot[C]{\emph{\thepage}} + % This adds a "DRAFT" footer to every normal page. (The first page of each chapter is not a "normal" page.) Page numbers are also printed on the right side. $if(draft)$ \fancyfoot[C]{\emph{DRAFT: \today}} @@ -275,18 +277,25 @@ \newlist{abbrv}{itemize}{1} \setlist[abbrv,1]{label=,labelwidth=1in,align=parleft,itemsep=0.1\baselineskip,leftmargin=!} +% Packages used to display math \usepackage{nicefrac} \usepackage{amsmath} \usepackage{amssymb} +\usepackage{mathtools} \usepackage{textcomp} +\usepackage{adjustbox} % adjust things to page width + \usepackage{longtable} % Allows tables to span multiple pages (this package must be called before hyperref) +\usepackage{colortbl, xcolor} + % Allows cells to be colored. Required by kableExtra + \usepackage[font=small,labelfont=bf]{caption} % Nicer captions -\usepackage{multicol,multirow,array} +\usepackage{multicol,multirow,array,xparse,pdflscape} % Used to make multiple columns for the indices and for creating columns that span multiple rows in tables \usepackage{rotating} @@ -301,7 +310,10 @@ \usepackage{graphicx} \graphicspath{{figures/}{_bookdown_files/}} -\usepackage{xfrac} +\usepackage{float} % Use the 'float' package for table and figure alignment +\floatplacement{figure}{H} % Make every figure with caption = h + +\usepackage{blkarray} % Adding annotations to border for matrices %%%%%%%%%%%%%%%%%%%%%%%%%%% %% ACTUAL DOCUMENT HERE %% @@ -321,7 +333,9 @@ \vspace*{1cm} +$if(phd)$ \sffamily{Thesis No. $thesisno$} +$endif$ \vspace*{1cm} \sffamily\textbf{Supervisor: $supervisor$}\\ diff --git a/tests/testthat/test-bibstats.R b/tests/testthat/test-bibstats.R index 87de02f1..5c6d30e9 100644 --- a/tests/testthat/test-bibstats.R +++ b/tests/testthat/test-bibstats.R @@ -1,22 +1,22 @@ test_that("Bibstats works properly", { + testthat::skip_on_os("linux") rmarkdown::draft(file = "test", template = "syllabus", package = "iheiddown", create_dir = TRUE, edit = FALSE) expect_equal(percent_female(bib_file = "test/references.bib", - rmd_file = "test/test.Rmd", - by = "author"), + rmd_file = "test/test.Rmd", by = "author"), "33% female authors") expect_equal(percent_female(bib_file = "test/references.bib", rmd_file = "test/test.Rmd", by = "publication"), "50% female authors") expect_equal(mean_year(bib_file = "test/references.bib", - rmd_file = "test/test.Rmd"), + rmd_file = "test/test.Rmd"), "Average date of publication: 1934") expect_equal(total_pages(bib_file = "test/references.bib", - rmd_file = "test/test.Rmd"), + rmd_file = "test/test.Rmd"), "Total number of pages: 7") expect_equal(mean_pages(bib_file = "test/references.bib", - rmd_file = "test/test.Rmd"), + rmd_file = "test/test.Rmd"), "Average number of pages: 7") unlink("test", recursive = TRUE) })