Skip to content

Commit

Permalink
Use markdown::html_format for vignettes so that Pandoc is not needed.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmurdoch committed Dec 7, 2023
1 parent 5db98f6 commit 6650030
Show file tree
Hide file tree
Showing 17 changed files with 91 additions and 104 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ jobs:

steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-pandoc@v2

- name: Install dependencies on MacOS
if: runner.os == 'macOS'
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/R-CMD-fullcheck.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ jobs:
steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/R-CMD-nosoft-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ jobs:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
rtools-version: ${{ matrix.config.rtools-version }}

- uses: r-lib/actions/setup-pandoc@v2

- name: Install automake
if: runner.os == 'macOS'
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/R-CMD-oldwincheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ jobs:
steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ jobs:
steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true
Expand Down
10 changes: 5 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: rgl
Version: 1.2.8
Version: 1.2.9
Title: 3D Visualization Using OpenGL
Authors@R: c(person("Duncan", "Murdoch", role = c("aut", "cre"),
email = "murdoch.duncan@gmail.com"),
Expand All @@ -26,7 +26,8 @@ Authors@R: c(person("Duncan", "Murdoch", role = c("aut", "cre"),
person("Michael", "Sumner", role = "ctb"),
person("Mike", "Stein", role = "ctb"))
Depends: R (>= 3.3.0)
Suggests: MASS, rmarkdown (>= 2.16), deldir (>= 1.0-4), orientlib, lattice, misc3d,
Suggests: MASS, markdown (>= 1.12),
rmarkdown (>= 2.16), deldir (>= 1.0-4), orientlib, lattice, misc3d,
magick, plotrix (>= 3.7-3), tripack, interp, alphashape3d, tcltk,
js (>= 1.2), webshot2 (>= 0.1.0), downlit (>= 0.4.0), pkgdown (>= 2.0.0), extrafont,
shiny, manipulateWidget (>= 0.9.0), testthat, markdown,
Expand All @@ -46,10 +47,9 @@ URL: https://github.com/dmurdoch/rgl,
SystemRequirements: OpenGL and GLU Library (Required for
display in R. See "Installing OpenGL support" in README.md.
Not needed if only browser displays using rglwidget() are wanted.),
zlib (optional), libpng (>=1.2.9, optional), FreeType (optional),
pandoc (>=1.14, needed for vignettes)
zlib (optional), libpng (>=1.2.9, optional), FreeType (optional)
BugReports: https://github.com/dmurdoch/rgl/issues
VignetteBuilder: knitr, rmarkdown
Biarch: true
RoxygenNote: 7.2.2.9000
RoxygenNote: 7.2.3
Roxygen: list(markdown = TRUE)
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# rgl 1.2.8
# rgl 1.2.9

## Minor changes

* ARIA support now declares `rgl` scenes with `role = "img"`.
* The vignettes in this package now use
`markdown::html_format`, so they no longer require Pandoc
(though Pandoc-using output formats like `html_document` will still be supported).

## Bug fixes

Expand Down
124 changes: 56 additions & 68 deletions R/knitr.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ hook_rgl <- function(before, options, envir) {
margin <- options$rgl.margin
if (is.null(margin)) margin <- 100
par3d(windowRect = margin + options$dpi *
c(0, 0, options$fig.width, options$fig.height))
c(0, 0, options$fig.width, options$fig.height))
Sys.sleep(.05) # need time to respond to window size change

dir <- knitr::opts_knit$get("base_dir")
if (is.character(dir)) {
if (!file_test("-d", dir)) dir.create(dir, recursive = TRUE)
Expand Down Expand Up @@ -114,9 +114,9 @@ save_rgl <- function(name, devices) {
# Evaluate an expression using our own private stream of
# randomness (not affected by set.seed).
withPrivateSeed <- local({

ownSeed <- NULL

function(expr) {
# Save the old seed if present.
if (exists(".Random.seed", envir = .GlobalEnv, inherits = FALSE)) {
Expand All @@ -125,7 +125,7 @@ withPrivateSeed <- local({
} else {
hasOrigSeed <- FALSE
}

# Swap in the private seed.
if (is.null(ownSeed)) {
if (hasOrigSeed) {
Expand All @@ -135,11 +135,11 @@ withPrivateSeed <- local({
} else {
.GlobalEnv$.Random.seed <- ownSeed
}

# On exit, save the modified private seed, and put the old seed back.
on.exit({
ownSeed <<- .GlobalEnv$.Random.seed

if (hasOrigSeed) {
.GlobalEnv$.Random.seed <- origSeed
} else {
Expand All @@ -149,7 +149,7 @@ withPrivateSeed <- local({
# commented it out.
# Need to call this to make sure that the value of .Random.seed gets put
# into R's internal RNG state. (Issue #1763)

# httpuv::getRNGState() # nolint
})

Expand Down Expand Up @@ -177,32 +177,20 @@ fns <- local({
setupKnitr <- function(autoprint = FALSE,
rgl.newwindow = autoprint,
rgl.closewindows = autoprint) {

# R produces multiple vignettes in the same session.
# Watch out for leftovers

if (!is.null(setupDone)) {
if (setupDone$autoprint) {
message("undoing setup")
options(saveopts)
saveopts <<- NULL
setupDone <<- NULL
}
}

if (!is.null(setupDone)) {
if (setupDone$autoprint != autoprint ||
setupDone$rgl.newwindow != rgl.newwindow ||
setupDone$rgl.closewindows != rgl.closewindows) {
warning("Already set autoprint = ", setupDone$autoprint,
", rgl.newwindow = ", setupDone$rgl.newwindow,
", rgl.closewindows = ", setupDone$rgl.closewindows)
}
return()
}
options(saveopts)
saveopts <<- NULL
counter <<- 0L
}

setupDone <<- list(autoprint = autoprint,
rgl.newwindow = rgl.newwindow,
rgl.closewindows = rgl.closewindows)

# R produces multiple vignettes in the same session.
knitr::opts_chunk$set(rgl.newwindow = rgl.newwindow,
rgl.closewindows = rgl.closewindows,
rgl.chunk = TRUE)
Expand Down Expand Up @@ -239,49 +227,49 @@ fns <- local({
} else
invisible(x)
}

sew.rglRecordedplot <- function(x, options = list(), ...) {
latex <- identical(opts_knit$get("out.format"), "latex") || identical(opts_knit$get("rmarkdown.pandoc.to"), "latex")
scene <- x$scene
doSnapshot <- knitrNeedsSnapshot(options)
content <- rglwidget(scene,
width = x$width,
height = x$height,
webgl = !doSnapshot)
if (inherits(content, "knit_image_paths")) {
# # We've done a snapshot, put it in the right place.
name <- fig_path("-rgl.png", options, rgl_counter())
if (!file_test("-d", dirname(name)))
dir.create(dirname(name), recursive = TRUE)
file.copy(content, name, overwrite = TRUE)
unlink(content)
content <- structure(list(file = name,
extension = "png"),
class = "html_screenshot")
}
fig.align <- options$fig.align
if (length(fig.align) == 1 && fig.align != "default")
content <- prependContent(content,
tags$style(sprintf(
"#%s {%s}",
content$elementId,
switch(fig.align,
center = "margin:auto;",
left = "margin-left:0;margin-right:auto;",
right = "margin-left:auto;margin-right:0;",
""))))
result <- do.call("knit_print", c(list(content, options), x$args))
if (!latex)
class(result) <- c(class(result), "knit_asis_htmlwidget")

sew(result, options)

sew.rglRecordedplot <- function(x, options = list(), ...) {
latex <- identical(opts_knit$get("out.format"), "latex") || identical(opts_knit$get("rmarkdown.pandoc.to"), "latex")
scene <- x$scene
doSnapshot <- knitrNeedsSnapshot(options)
content <- rglwidget(scene,
width = x$width,
height = x$height,
webgl = !doSnapshot)
if (inherits(content, "knit_image_paths")) {
# # We've done a snapshot, put it in the right place.
name <- fig_path("-rgl.png", options, rgl_counter())
if (!file_test("-d", dirname(name)))
dir.create(dirname(name), recursive = TRUE)
file.copy(content, name, overwrite = TRUE)
unlink(content)
content <- structure(list(file = name,
extension = "png"),
class = "html_screenshot")
}
fig.align <- options$fig.align
if (length(fig.align) == 1 && fig.align != "default")
content <- prependContent(content,
tags$style(sprintf(
"#%s {%s}",
content$elementId,
switch(fig.align,
center = "margin:auto;",
left = "margin-left:0;margin-right:auto;",
right = "margin-left:auto;margin-right:0;",
""))))
result <- do.call("knit_print", c(list(content, options), x$args))
if (!latex)
class(result) <- c(class(result), "knit_asis_htmlwidget")

list(
setupKnitr = setupKnitr,
knit_print.rglOpen3d = knit_print.rglOpen3d,
knit_print.rglId = knit_print.rglId,
sew.rglRecordedplot = sew.rglRecordedplot)
sew(result, options)
}

list(
setupKnitr = setupKnitr,
knit_print.rglOpen3d = knit_print.rglOpen3d,
knit_print.rglId = knit_print.rglId,
sew.rglRecordedplot = sew.rglRecordedplot)
})

setupKnitr <- fns[["setupKnitr"]]
Expand Down
8 changes: 4 additions & 4 deletions README.Rmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
output: github_document
output:
markdown::html_format
---

<!-- README.md is generated from README.Rmd. Please edit that file -->
Expand All @@ -16,9 +17,8 @@ knitr::opts_chunk$set(
options(rgl.useNULL=TRUE)
suppressPackageStartupMessages(library(rgl))
if (!requireNamespace("rmarkdown", quietly = TRUE) ||
!rmarkdown::pandoc_available("1.14")) {
warning(call. = FALSE, "These vignettes assume rmarkdown and pandoc version 1.14. These were not found. Older versions will not work.")
if (!requireNamespace("rmarkdown", quietly = TRUE)) {
warning(call. = FALSE, "These vignettes assume rmarkdown. This was not found.")
knitr::knit_exit()
}
setupKnitr(autoprint = TRUE)
Expand Down
5 changes: 0 additions & 5 deletions man/setupKnitr.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ or \code{\link{highlevel}} functions. All RGL functions that
produce graphics do this, but functions in other packages that
call them may not return values appropriately.
If you have multiple calls to \code{setupKnitr()}, all
should have the same arguments. If any differ, a
warning will be issued, and the first set of arguments
will be used.
Mixing explicit calls
to \code{\link{rglwidget}} with auto-printing is likely to lead to failure of some
scenes to display. To avoid this, set \code{options(rgl.printRglwidget = FALSE)} before using such explicit calls. Similarly,
Expand Down
3 changes: 3 additions & 0 deletions vignettes/WebGL.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ title: "User Interaction in WebGL (updated)"
author: "Duncan Murdoch"
date: "`r format(Sys.time(), '%B %d, %Y')`"
output:
markdown::html_format:
options:
toc: true
rmarkdown::html_vignette:
toc: yes
fig_width: 5
Expand Down
5 changes: 3 additions & 2 deletions vignettes/demos.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
title: "rgl Demos"
date: "`r Sys.Date()`"
output:
rmarkdown::html_vignette:
toc: true
markdown::html_format:
options:
toc: true
vignette: >
%\VignetteIndexEntry{rgl Demos}
%\VignetteEngine{knitr::rmarkdown}
Expand Down
3 changes: 3 additions & 0 deletions vignettes/deprecation.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ title: "Deprecating the `rgl.*` interface"
author: "Duncan Murdoch"
date: "`r Sys.Date()`"
output:
markdown::html_format:
options:
toc: true
rmarkdown::html_vignette:
toc: true
vignette: >
Expand Down
8 changes: 5 additions & 3 deletions vignettes/pkgdown.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
title: "Using RGL in pkgdown web sites"
author: "Duncan Murdoch"
output:
markdown::html_format:
options:
toc: true
rmarkdown::html_vignette:
fig_height: 5
fig_width: 5
Expand All @@ -18,9 +21,8 @@ vignette: >
---

```{r setup, include=FALSE}
if (!requireNamespace("rmarkdown", quietly = TRUE) ||
!rmarkdown::pandoc_available("1.14")) {
warning(call. = FALSE, "These vignettes assume rmarkdown and pandoc version 1.14. These were not found. Older versions will not work.")
if (!requireNamespace("rmarkdown", quietly = TRUE)) {
warning(call. = FALSE, "These vignettes assume rmarkdown. This was not found.")
knitr::knit_exit()
}
knitr::opts_chunk$set(echo = TRUE)
Expand Down
3 changes: 3 additions & 0 deletions vignettes/rgl.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ title: "rgl Overview"
author: "Duncan Murdoch"
date: "`r format(Sys.time(), '%B %d, %Y')`"
output:
markdown::html_format:
options:
toc: true
rmarkdown::html_vignette:
fig_height: 5
fig_width: 5
Expand Down
5 changes: 2 additions & 3 deletions vignettes/setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ suppressPackageStartupMessages(library(rgl))
options(rgl.useNULL=TRUE)
options(rgl.printRglwidget=FALSE)

if (!requireNamespace("rmarkdown", quietly = TRUE) ||
!rmarkdown::pandoc_available("1.14")) {
warning(call. = FALSE, "These vignettes assume rmarkdown and pandoc version 1.14. These were not found. Older versions will not work.")
if (!requireNamespace("rmarkdown", quietly = TRUE)) {
warning(call. = FALSE, "These vignettes assume rmarkdown is installed. It was not found.")
knitr::knit_exit()
}

Expand Down
Loading

0 comments on commit 6650030

Please sign in to comment.