Skip to content

Commit

Permalink
Merge pull request #127 from jhollway/develop
Browse files Browse the repository at this point in the history
Fixed CRAN issues with errors related to API rate limits (patch fix)
  • Loading branch information
henriquesposito authored Sep 21, 2022
2 parents 4683599 + 26ab4dc commit 7d73335
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 29 deletions.
14 changes: 9 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 12 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion R/bibfix.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 22 additions & 10 deletions R/bibstats.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#' @importFrom bib2df bib2df
#' @importFrom utils install.packages
#' @return Prints a summary statistic (e.g. mean or proportion)
#'
NULL

#' @rdname bibstats
Expand All @@ -40,30 +39,36 @@ 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)
authors <- stringr::str_remove(authors, "^.+, \\{")
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))) {
Expand All @@ -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")
}
}
}

Expand Down
10 changes: 8 additions & 2 deletions R/poster_html.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion R/theme.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
3 changes: 1 addition & 2 deletions cran-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@

0 errors | 0 warnings | 0 notes

- Fixed issue relating to tests on Linux

- Added informative message for when rate limits are reached with `percent_female()`
18 changes: 16 additions & 2 deletions inst/rmarkdown/templates/thesis_pdf/resources/template.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down Expand Up @@ -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}
Expand All @@ -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 %%
Expand All @@ -321,7 +333,9 @@

\vspace*{1cm}

$if(phd)$
\sffamily{Thesis No. $thesisno$}
$endif$

\vspace*{1cm}
\sffamily\textbf{Supervisor: $supervisor$}\\
Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/test-bibstats.R
Original file line number Diff line number Diff line change
@@ -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)
})
Expand Down

0 comments on commit 7d73335

Please sign in to comment.