Skip to content

Commit ba203de

Browse files
author
Noam Ross
committed
Simplify joss_article function
1 parent 2d9d385 commit ba203de

File tree

3 files changed

+28
-54
lines changed

3 files changed

+28
-54
lines changed

R/joss_article.R

Lines changed: 20 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,18 @@
66
#' articles as markdown, this format can be used to generate markdown from
77
#' R Markdown and to locally preview how the article will appear as PDF.
88
#'
9+
#' The following variables may be set in YAML metadata to populate fields in the
10+
#' article PDF: \code{doi, year, volume, issue, page, submitted, published,
11+
#' review_url, repository}, and \code{archive_doi}.
12+
#'
913
#' @inheritParams rmarkdown::pdf_document
1014
#' @param journal one of "JOSS" or"JOSE"
1115
#' @param keep_md Whether to retain the intermediate markdown and images.
1216
#' Defaults to TRUE.
13-
#' @param doi,year,volume,issue,page,submitted,published,review_url,repository,archive_doi
14-
#' Article metadata, all optional for generating PDF preview, auto-generated
15-
#' on submission.
1617
#' @param latex_engine,... Arguments passed to \code{rmarkdown::pdf_document}
1718
#' @export
1819
joss_article <- function(journal = "JOSS",
1920
keep_md = TRUE,
20-
doi = "",
21-
year = "",
22-
volume = "",
23-
issue = "",
24-
page = "",
25-
submitted = "",
26-
published = "",
27-
review_url = "",
28-
repository = "",
29-
archive_doi = "",
3021
latex_engine = "xelatex",
3122
...) {
3223

@@ -38,52 +29,34 @@ joss_article <- function(journal = "JOSS",
3829
"Journal of Open Source Software",
3930
"Journal of Open Source Education")
4031

41-
template_variables <- c(
42-
paste0("logo_path=", logo_path),
43-
paste0("year=", year),
44-
paste0("journal_name=", journalname),
45-
paste0("formatted_doi=", doi),
46-
paste0("archive_doi=https://doi.org/", archive_doi),
47-
paste0("review_issue_url=", review_url),
48-
paste0("repository=", repository),
49-
paste0("submitted=", submitted),
50-
paste0("published=", published),
51-
paste0("issue=", issue),
52-
paste0("volume=", volume),
53-
paste0("page=", page),
54-
"graphics=true"
55-
)
56-
57-
template_variables <- c(rbind(rep("-V", length(template_variables)),
58-
template_variables))
59-
6032
pandoc_args <- c(
61-
template_variables,
33+
"-V", paste0("logo_path=", logo_path),
34+
"-V", paste0("journal_name=", journalname),
35+
"-V", "graphics=true",
6236
"--csl", find_resource("joss_article", "apa.csl")
6337
)
6438

6539
base <- pdf_document_format(
6640
"joss_article",
6741
latex_engine = latex_engine,
6842
pandoc_args = pandoc_args,
69-
citation_package = "none"
70-
)
43+
citation_package = "none",
44+
fig_width = 6, fig_height = 4.15,
45+
dev = "png"
7146

72-
base$knitr$opts_chunk$dev <- c("png")
73-
base$knitr$opts_chunk$dpi <- 300
74-
base$knitr$opts_chunk$fig.width <- 6
75-
base$knitr$opts_chunk$fig.height <- 4.15
47+
)
7648
base$keep_md <- keep_md
7749
base$clean_supporting <- !keep_md
7850

79-
base$post_knit <- function(metadata, imput_file, runtime, ...) {
80-
citation_author <- ifelse(
81-
length(metadata$authors) > 1,
82-
paste(metadata$authors[[1]]$name, "et. al."),
83-
metadata$authors[[1]]$name
84-
)
85-
86-
c("-V", paste0("citation_author=", citation_author))
51+
base$post_knit <- function(metadata, input_file, runtime, ...) {
52+
if (!is.null(metadata$authors)) {
53+
citation_author <- ifelse(
54+
length(metadata$authors) > 1,
55+
paste(metadata$authors[[1]]$name, "et. al."),
56+
metadata$authors[[1]]$name
57+
)
58+
return(c("-V", paste0("citation_author=", citation_author)))
59+
}
8760
}
8861

8962
base

man/joss_article.Rd

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testit/test-formats.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ test_format("asa_article")
3434
test_format("biometrics_article")
3535
test_format("elsevier_article")
3636
test_format("jss_article")
37+
test_format("joss_article")
3738
test_format("rss_article")
3839
test_format("pnas_article")
3940
test_format("ieee_article")

0 commit comments

Comments
 (0)