Skip to content

Commit

Permalink
Merge branch 'main' of github.com:rjournal/rjtools
Browse files Browse the repository at this point in the history
  • Loading branch information
huizezhang-sherry committed Jan 3, 2024
2 parents b453331 + 5f0fe0d commit 1384370
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 59 deletions.
17 changes: 10 additions & 7 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# rjtools 1.0.12

* Updates for accessibility based on updates in distill package.
* File structure for template article is now cleaner, with data, figures, scripts, motivation-letter, folders.
* Added `rjournal_article()` as a preferred alias to `rjournal_web_article()`
since this output format generally produces both HTML and PDF outputs.
* check functions updated, including DOIs in references, title case in bib file, existence of csl file
* reference to new web site in the documentation
* new function to assist authors prepare for a release
* style to better adhere to accessibility standards
* remove link to twitter/x
* handling of longtable
* utilise system sty file, not author supplied
* This is reflected in the change in the YAML header to be `rjtools::rjournal_article`. This generates both html and pdf. `rjtools::rjournal_web_article`, which will now only generate the html. `rjtools::rjournal_pdf_article` now only generates the pdf.
* Check functions updated, including DOIs in references, title case in bib file, existence of csl file
* Reference to new web site in the documentation.
* New function to assist authors prepare for a release.
* Style to better adhere to accessibility standards.
* Remove link to twitter/x.
* Handling of longtable.
* Utilise system sty file, not author supplied.

# rjtools 1.0.11

Expand Down
38 changes: 27 additions & 11 deletions R/rj_article.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
#' and `rticles::rjournal_article()` for pdf articles.
#' @inheritParams distill::distill_article
#' @param legacy_pdf whether an article is from the past and only have pdf version
#' @param web_only additional param for embedding PDF or using Rmd to produce HTML
#' @importFrom rlang caller_env env_poke
#' @return the rendered R Journal article
#' @export
#' @rdname rjournal_article
rjournal_article <- function(toc = FALSE, self_contained = FALSE,
legacy_pdf = FALSE, web_only = !legacy_pdf, ...) {
legacy_pdf = FALSE, ...) {
args <- c()
base_format <- distill::distill_article(
self_contained = self_contained, toc = toc, ...
Expand All @@ -34,9 +33,14 @@ rjournal_article <- function(toc = FALSE, self_contained = FALSE,
base_format$post_knit <- function(metadata, input_file, runtime, ...) {
# Modify YAML metadata for pre-processor
render_env <- rlang::caller_env(n = 2)
# FIXME: renames abstract to description and then later hacks around it by creating
# a d-abstract html element by hand in JS (rjdistill.html). This
# is incredibly fragile, because the element has no idenficiation tag,
# so this should be cleaned up so we can have distill create d-abstract directly...
metadata <- replace_names(metadata, c("abstract" = "description"))
metadata$title <- strip_macros(metadata$title)
metadata$description <- strip_macros(metadata$description %||% paste0('"', metadata$title, '" published in The R Journal.'))
if (is.null(metadata$subtitle)) ## the tools don't support both abstract and subtitle
metadata$description <- strip_macros(metadata$description %||% paste0('"', metadata$title, '" published in The R Journal.'))
for(i in seq_along(metadata$author)) {
metadata$author[[i]] <- replace_names(metadata$author[[i]], c("orcid" = "orcid_id"))
}
Expand Down Expand Up @@ -106,7 +110,7 @@ rjournal_article <- function(toc = FALSE, self_contained = FALSE,
ctvs <- local_cache$get("ctv")
} else {
ctvs <- readRDS(
gzcon(url("https://cran.r-project.org/src/contrib/Views.rds", open = "rb"))
gzcon(url(.cran("/src/contrib/Views.rds"), open = "rb"))
)
local_cache$add(ctvs, "ctv")
}
Expand Down Expand Up @@ -148,8 +152,13 @@ rjournal_article <- function(toc = FALSE, self_contained = FALSE,
pre_processor <- function(metadata, input_file, runtime, knit_meta, files_dir,
output_dir) {

# Add embedded PDF
embed_pdf <- if(! web_only){
input <- xfun::read_utf8(input_file)
front_matter_delimiters <- grep("^(---|\\.\\.\\.)\\s*$", input)
body <- input[(front_matter_delimiters[2]+1):length(input)]

# Add embedded PDF to HTML stubs
is_stub <- !any(grepl("^\\s*#+\\s*.*", body))
embed_pdf <- if(isTRUE(metadata$tex_native) || (legacy_pdf && is_stub)) {
whisker::whisker.render(
'<div class="l-page">
<embed src="{{slug}}.pdf" type="application/pdf" height="955px" width="100%">
Expand Down Expand Up @@ -184,7 +193,7 @@ rjournal_article <- function(toc = FALSE, self_contained = FALSE,
data <- c(data, list(BIOC = BIOC))
}
}
if (web_only && legacy_pdf) {
if (FALSE && legacy_pdf) {
TEXOR <- "This article is converted from a Legacy LaTeX article using the
[texor](https://cran.r-project.org/package=texor) package.
The pdf version is the official version. To report a problem with the html,
Expand All @@ -195,16 +204,13 @@ rjournal_article <- function(toc = FALSE, self_contained = FALSE,
template <- xfun::read_utf8(system.file("appendix.md", package = "rjtools"))
appendix <- whisker::whisker.render(template, data)

input <- xfun::read_utf8(input_file)
front_matter_delimiters <- grep("^(---|\\.\\.\\.)\\s*$", input)

xfun::write_utf8(
c(
"---",
yaml::as.yaml(metadata),
"---",
"",
if(! web_only) embed_pdf else input[(front_matter_delimiters[2]+1):length(input)],
c(embed_pdf, body),
"",
appendix
),
Expand Down Expand Up @@ -330,3 +336,13 @@ rjournal_article <- function(toc = FALSE, self_contained = FALSE,
base_format = base_format
)
}

.cran <- function(path="") {
cran <- "http://cran.R-project.org"
rep <- getOption("repos")
if ("CRAN" %in% names(rep)) {
opt <- rep["CRAN"]
if (opt != "@CRAN@") cran <- opt
}
paste0(cran, path)
}
13 changes: 11 additions & 2 deletions R/rj_pdf_article.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ rjournal_pdf_article <- function(..., self_contained = FALSE) {
}
pre_processor <- fmt$pre_processor
fmt$pre_processor <- function(front_matter, input, ...) {
if(!is.null(front_matter$bibliography)) {
if(!is.null(front_matter$bibliography) && !isTRUE(front_matter$tex_native)) {
xfun::write_utf8(
c(xfun::read_utf8(input), "\n# References\n"),
input
Expand All @@ -51,7 +51,6 @@ rjournal_pdf_article <- function(..., self_contained = FALSE) {
file.rename(filename, filename2)
filename <- filename2
}

# Copy purl-ed R file with the correct name
dest_file <- xfun::with_ext(filename, "R")
our_file <- TRUE
Expand Down Expand Up @@ -79,6 +78,16 @@ rjournal_pdf_article <- function(..., self_contained = FALSE) {
temp_tex <- xfun::read_utf8(output_file)
# Add author line
temp_tex <- post_process_authors(temp_tex)
## remove CLS references if we are using native ones
## coversely, if CLS is already included, don't add TeX ones
if (isTRUE(metadata$tex_native)) {
cls.b <- grep("^\\\\begin\\{CSLReferences\\}", temp_tex)
cls.e <- grep("^\\\\end\\{CSLReferences\\}", temp_tex)
if (length(cls.b) == 1 && length(cls.e) == 1 && cls.b < cls.e)
temp_tex <- temp_tex[-(cls.b:cls.e)]
} else if (length(grep("^\\\\begin\\{CSLReferences\\}", temp_tex)) &&
length(bil <- grep("^\\\\bibliography", temp_tex)))
temp_tex <- temp_tex[-bil]
xfun::write_utf8(temp_tex, output_file)

# Bookdown post-processing, silently capture error as it will attempt to
Expand Down
8 changes: 7 additions & 1 deletion R/rj_web_article.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#' @export
#' @rdname rjournal_article
rjournal_web_article <- rjournal_article
rjournal_web_article <- function(toc = FALSE, self_contained = FALSE, ...) {
base_format <- rjournal_article(
self_contained = self_contained, toc = toc, ...
)
base_format$on_exit <- function() {}
base_format
}
20 changes: 16 additions & 4 deletions R/rj_web_issue.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ rjournal_web_issue <- function(toc = FALSE, self_contained = FALSE, rnews = FALS
args
}

args <- c(
rmarkdown::pandoc_include_args(
in_header = system.file("rjdistill.html", package = "rjtools")
)
)

on_exit <- function() {
# Deactivate for now as I am not sure to understand what should be built
# if (!is.null(render_pdf) && !legacy_pdf) {
Expand All @@ -124,7 +130,13 @@ rjournal_web_issue <- function(toc = FALSE, self_contained = FALSE, rnews = FALS

rmarkdown::output_format(
knitr = NULL, # use base one
pandoc = list(),

pandoc = list(
args = args,
lua_filters = c(
system.file("latex-pkg.lua", package = "rjtools")
)
),
keep_md = NULL, # use base one
clean_supporting = NULL, # use base one
pre_knit = NULL,
Expand All @@ -140,7 +152,7 @@ list_issue_articles <- function(volume, issue, rnews = FALSE) {
prefix <- if(rnews) "RN" else "RJ"
articles <- list.files(
list.dirs("../../_articles", recursive = FALSE),
paste0(prefix, "-\\d{4}-\\d{3}\\.(r|R)md"),
paste0(prefix, "-\\d{4}-\\d{3}\\.[Rr]md$"),
full.names = TRUE
)

Expand Down Expand Up @@ -194,7 +206,7 @@ news_entry <- function(art) {
art$author <- vapply(art$author, function(z) z$name %||% paste(z$first_name, z$last_name), character(1L))
}
stringr::str_glue(
"[{art$title}](../../news/{art$slug})<br>{glue::glue_collapse(art$author, sep = ', ', last = ' and ')} {art$journal$firstpage %||% art$pages[1] %||% \"\"}\n\n"
"[{art$title}](../../news/{art$slug}/)<br>{glue::glue_collapse(art$author, sep = ', ', last = ' and ')} {art$journal$firstpage %||% art$pages[1] %||% \"\"}\n\n"
)
}

Expand All @@ -219,7 +231,7 @@ article_entry <- function(art) {
}

stringr::str_glue(
"[{art$title}](../../articles/{art$slug})<br>{glue::glue_collapse(art$author, sep = ', ', last = ' and ')} {art$journal$firstpage %||% art$pages[1] %||% \"\"}\n\n"
"[{art$title}](../../articles/{art$slug}/)<br>{glue::glue_collapse(art$author, sep = ', ', last = ' and ')} {art$journal$firstpage %||% art$pages[1] %||% \"\"}\n\n"
)
}

Expand Down
6 changes: 3 additions & 3 deletions R/submit-rjournal.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#' Submit a paper to the R Journal
#'
#' This is a last-minute self-serve check function, similar to
#' [devtools::release()], for handling R Journal styling that can be difficult
#' with automatic checks.
#' This is a final self-check function, similar to
#' that runs through a checklist on your submission
#' that cannot be done automatically.
#' @importFrom utils browseURL
#' @export
submit_rjournal <- function(){
Expand Down
29 changes: 24 additions & 5 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
This revision is to fix a problem identified by CRAN maintainers.
This revision has some changes to fix some errors, and streamline usage and submission operations.

## Test environment
## Test environment, using devtools::check_rhub()

* local R installation: R version 4.2.1 (2022-06-23)
* local R installation: R version 4.3.1 (2023-06-16)
* Ubuntu Linux 20.04.1 LTS, R-release, GCC
* Fedora Linux, R-devel, clang, gfortran
* Fedora Fedora Linux, R-devel, clang, gfortran
* Windows Server 2022, R-devel, 64 bit

## R CMD check results
── R CMD check results ──────────────────────────────────── rjtools 1.0.12 ────
Duration: 29.9s

0 errors ✔ | 0 warnings ✔ | 0 notes ✔

With check_rhub, there are two notes, which I believe can be ignored.

── rjtools 1.0.12: NOTE

Build ID: rjtools_1.0.12.tar.gz-0420bebe3d074a298f5056193567f16e
Platform: Windows Server 2022, R-devel, 64 bit
Submitted: 2h 53m 53.5s ago
Build time: 6m 12.7s

❯ checking for non-standard things in the check directory ... NOTE
Found the following files/directories:
''NULL''

❯ checking for detritus in the temp directory ... NOTE
Found the following files/directories:
'lastMiKTeXException'

0 errors ✔ | 0 warnings ✔ | 2 notes ✖
41 changes: 34 additions & 7 deletions inst/rjdistill.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@
buttons.append('<a href="' + slug + '.pdf" class="dt-tag"><i class="fas fa-file-pdf"></i> PDF</a>')
buttons.append('<a href="' + slug + '.zip" class="dt-tag"><i class="fas fa-file-zipper"></i> Supplement</a>')


const abstract = $('<d-abstract>')
abstract.append('<b>Abstract:</b><br>')
abstract.append($("d-title p:not(:empty)").first()) // Move description to d-abstract
$("d-title p:empty").remove() // Remove empty paragraphs after title
abstract.append(buttons)
abstract.insertAfter($('d-title')) // Add abstract section after title
// adds Abstract: in front of the first <p> in the title section --
// unless it happens to be the subtitle (FIXME: this is a bad hack - can't distill do this?)
var tpar = $("d-title p:not(:empty)").first();
if (tpar && ! tpar.hasClass("subtitle")) {
const abstract = $('<d-abstract>')
abstract.append('<b>Abstract:</b><br>')
abstract.append($("d-title p:not(:empty)").first()) // Move description to d-abstract
$("d-title p:empty").remove() // Remove empty paragraphs after title
abstract.append(buttons)
abstract.insertAfter($('d-title')) // Add abstract section after title */
}

// tweak by-line
var byline = $("d-byline div.byline")
Expand Down Expand Up @@ -142,4 +146,27 @@
color: rgb(60, 60, 60);
}

d-article h2 {
border-bottom: 0px solid rgba(0, 0, 0, 0.1);
padding-bottom: 0rem;
}
d-article h3 {
font-size: 20px;
}
d-article h4 {
font-size: 18px;
text-transform: none;
}

@media (min-width: 1024px) {
d-article h2 {
font-size: 32px;
}
d-article h3 {
font-size: 24px;
}
d-article h4 {
font-size: 20px;
}
}
</style>
1 change: 1 addition & 0 deletions inst/tex/RJournal.sty
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
%
\RequirePackage[sectionbib,round]{natbib}
\bibliographystyle{abbrvnat}
\renewcommand{\bibsection}{\section*{References}}

% Equations, figures and tables are counted within articles, but we do
% not show the article number. For equations it becomes a bit messy to avoid
Expand Down
18 changes: 2 additions & 16 deletions man/rjournal_article.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/submit_rjournal.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1384370

Please sign in to comment.