Skip to content

Commit 8f9edee

Browse files
committed
Address CRAN issues
1 parent 5a28c7d commit 8f9edee

File tree

5 files changed

+61
-14
lines changed

5 files changed

+61
-14
lines changed

.Rbuildignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
^inst/threeBrainJS/old
2222
^inst/threeBrainJS/src
2323
^inst/threeBrainJS/dist/[0-9]+.threebrain-[a-zA-Z0-9]+.js
24-
^inst/threeBrainJS/dist/threebrain-main\.js\.mapp$
25-
^inst/threeBrainJS/dist/threebrain-worker\.js\.mapp$
24+
^inst/threeBrainJS/dist/threebrain-main\.js\.map$
25+
^inst/threeBrainJS/dist/threebrain-worker\.js\.map$
2626
^inst/threeBrainJS/build\.sh
2727
^inst/threeBrainJS/package
2828
^inst/threeBrainJS/webpack

R/class_electrode_proto.R

+2-1
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,8 @@ ElectrodePrototype <- R6::R6Class(
511511
if(with_texture && !is.null(self$.last_texture)) {
512512
texture_file <- file.path(tempdir(check = TRUE), sprintf("%s.png", private$id))
513513
grDevices::png(filename = texture_file, units = "px", width = 256, height = 256)
514-
graphics::par(mar = c(0,0,0,0))
514+
oldpar <- graphics::par(mar = c(0, 0, 0, 0))
515+
on.exit({ graphics::par(oldpar) })
515516
self$preview_texture(...)
516517
grDevices::dev.off()
517518
texture_file <- normalizePath(texture_file)

R/ext_media.R

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ video_content <- function(path, duration = Inf, time_start = 0, asp_ratio = 16 /
3333
if( local ){
3434
# try to download video because path is probably an URL
3535
url <- path
36-
timeout <- getOption("timeout", 60)
37-
on.exit({
38-
options("timeout" = timeout)
39-
})
40-
options("timeout" = 6000)
36+
37+
# 60s is too short to download a video
38+
oldopt <- options("timeout" = 6000)
39+
on.exit({ options(oldopt) })
40+
4141
path <- tempfile(fileext = '.mp4')
4242
utils::download.file(url, destfile = path)
4343
temp <- TRUE

R/plot_volume-slices.R

+7-3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ plot_slices <- function(
5454
# overlays <- list.files(root_path, pattern = "\\.nii.gz$", full.names = TRUE)
5555
# overlay_alpha <- 0.3
5656

57+
# Make sure `par` is reset on exit
58+
oldpar <- graphics::par(no.readonly = TRUE)
59+
on.exit({ graphics::par(oldpar) })
60+
5761
title_position <- match.arg(title_position)
5862

5963
if( is.character(volume) ) {
@@ -182,8 +186,6 @@ plot_slices <- function(
182186

183187
pos <- rbind(t(as.matrix(expand.grid(x, x, KEEP.OUT.ATTRS = FALSE))), 0, 1)
184188

185-
oldpar <- graphics::par(no.readonly = TRUE)
186-
187189
if(!length(nc) || is.na(nc[[1]])) {
188190
nc <- grDevices::n2mfrow(npts, asp = 1/n_plots)[[2]]
189191
} else {
@@ -223,14 +225,14 @@ plot_slices <- function(
223225
padding_top <- 0.8
224226
}
225227

228+
# The function calls on.exit({ graphics::par(oldpar) }) so no need to reset here
226229
graphics::par(
227230
bg = pal[[1]],
228231
fg = pal[[length(pal)]],
229232
col.main = pal[[length(pal)]],
230233
col.axis = pal[[1]],
231234
mar = c(0,0,0,0)
232235
)
233-
on.exit({ do.call(graphics::par, oldpar) })
234236
}
235237

236238
# Calculate plt
@@ -244,6 +246,8 @@ plot_slices <- function(
244246
ratio <- pin[[1]] / pin[[2]]
245247
plt <- c( 0, 1, 0.5 - ratio / 2, 0.5 + ratio / 2 )
246248
}
249+
250+
# The function calls on.exit({ graphics::par(oldpar) }) so no need to reset here
247251
adjust_plt <- function(reset = FALSE) {
248252
if( reset ) {
249253
graphics::par("plt" = c(0, 1, 0, 1))

cran-comments.md

+45-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,49 @@
33
## 2024-11-01
44
**Version 1.2.0 (current)**
55

6-
To address the `CRAN` issues:
6+
To address the `CRAN` issues (2024-11-05)
7+
8+
```
9+
\dontrun{} should only be used if the example really cannot be executed (e.g. because of missing additional software, missing API keys, ...) by the user. That's why wrapping examples in \dontrun{} adds the comment ("# Not run:") as a warning for the user. Does not seem necessary. Please replace \dontrun with \donttest.
10+
Please unwrap the examples if they are executable in < 5 sec, or replace dontrun{} with \donttest{}.
11+
-> create_group.Rd; freesurfer_brain.Rd; geom_freemesh.Rd
12+
```
13+
14+
Thanks, currently there are three `\dontrun{}` because these examples do require users to
15+
16+
* download additional data and software that are not licensed under, nor built into this package.
17+
* run the code in interactive sessions
18+
19+
I have also tried my best to provide toy-examples if possible. This package originally has lots of `dontrun`s and I have converted most of them to `donttest` back in version `0.1.2` (see comments down below). I believe these three `dontrun` cases have been left since then.
20+
21+
22+
```
23+
Please make sure that you do not change the user's options, par or working directory. If you really have to do so within functions, please ensure with an *immediate* call of on.exit() that the settings are reset when the function is exited.
24+
e.g.:
25+
...
26+
oldpar <- par(no.readonly = TRUE) # code line i
27+
on.exit(par(oldpar)) # code line i + 1
28+
...
29+
par(mfrow=c(2,2)) # somewhere after
30+
...
31+
e.g.: -> R/class_electrode_proto.R; R/ext_media.R; R/plot_volume-slices.R
32+
If you're not familiar with the function, please check ?on.exit. This function makes it possible to restore options before exiting a function even if the function breaks. Therefore it needs to be called immediately after the option change within a function.
33+
```
34+
35+
Thanks, I have added `on.exit` to all functions that change `options` and `par`.
36+
37+
Just in case you miss it, there are multiple lines changing `par` in the function `plot_slices` (`R/plot_volume-slices.R`), and I make sure the `par` remain unchanged via the following two lines at the very beginning.
38+
39+
```r
40+
oldpar <- graphics::par(no.readonly = TRUE)
41+
on.exit({ graphics::par(oldpar) })
42+
```
43+
44+
45+
46+
47+
48+
To address the previous `CRAN` issues (2024-11-01)
749

850
```
951
URL: https://cran.r-project.org/web/packages/threeBrain/index.html
@@ -22,7 +64,7 @@ Package `ravetools` has been updated and on `CRAN` now. The dependency is cleare
2264

2365
This package (`threeBrain`) is developed out of fun and used in my thesis and later projects. I am the solo developer in this project (wrote 99.99% code). Other contributors are explicitly claimed in the `DESCRIPTION`.
2466

25-
There is one external `JavaScript` library `three-brain-js`. The code is located at `inst/threeBrainJS`. I am also the main maintainer and contributor of that project. The distribution included is a compiled bundle that is released under `MPL-2.0` as a whole. As required, the license file has been included when `mpn` compiles the bundles, see `inst/threeBrainJS/dist`. There might some other external programs, but they can't claim the authorship of the release bundle. Their corresponding license files are included too.
67+
There is one external `JavaScript` library `three-brain-js`. The code is located at `inst/threeBrainJS`. I am also the main maintainer and contributor of that project. The distribution included is a compiled bundle that is released under `MPL-2.0` as a whole. As required, the license file has been included when `npm` compiles the bundles, see `inst/threeBrainJS/dist`. There might some other external programs, but they can't claim the authorship of the release bundle. Their corresponding license files are included too.
2668

2769

2870
Self check: 0 errors | 0 warnings | 1 note
@@ -130,7 +172,7 @@ Please fix and resubmit.
130172

131173
#### Solution:
132174

133-
* exported internal functions needed by exaples
175+
* exported internal functions needed by examples
134176
* changed dontrun to donttest
135177

136178

0 commit comments

Comments
 (0)