Skip to content

Commit

Permalink
Merge pull request #255 from R-Lum/on.exit
Browse files Browse the repository at this point in the history
Use add = TRUE with on.exit()
[skip ci]
  • Loading branch information
mcol authored Sep 18, 2024
2 parents 8d435dd + dee4f4f commit c9834f9
Show file tree
Hide file tree
Showing 28 changed files with 37 additions and 38 deletions.
2 changes: 1 addition & 1 deletion R/analyse_Al2O3C_CrossTalk.R
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ analyse_Al2O3C_CrossTalk <- function(

##get plot settings
par.default <- par(no.readonly = TRUE)
on.exit(par(par.default))
on.exit(par(par.default), add = TRUE)

##settings
plot_settings <- list(
Expand Down
2 changes: 1 addition & 1 deletion R/analyse_Al2O3C_Measurement.R
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ analyse_Al2O3C_Measurement <- function(
if (plot) {
##get plot settings
par.default <- par()$mfrow
on.exit(par(mfrow = par.default))
on.exit(par(mfrow = par.default), add = TRUE)

##settings
plot_settings <- list(
Expand Down
2 changes: 1 addition & 1 deletion R/analyse_FadingMeasurement.R
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ analyse_FadingMeasurement <- function(
if(plot) {
if (!plot.single[1]) {
par.default <- par()$mfrow
on.exit(par(mfrow = par.default))
on.exit(par(mfrow = par.default), add = TRUE)
par(mfrow = c(2, 2))

}
Expand Down
4 changes: 2 additions & 2 deletions R/analyse_IRSAR.RF.R
Original file line number Diff line number Diff line change
Expand Up @@ -1560,7 +1560,7 @@ analyse_IRSAR.RF<- function(

##grep par default and define reset
def.par <- par(no.readonly = TRUE)
on.exit(par(def.par))
on.exit(par(def.par), add = TRUE)

##set plot frame, if a method was chosen
if (any(method %in% c("SLIDE", "FIT", "VSLIDE"))) {
Expand All @@ -1575,7 +1575,7 @@ analyse_IRSAR.RF<- function(
}else{
if(plot.settings[["cex"]] != 1){
def.par <- par()[["cex"]]
on.exit(par(def.par))
on.exit(par(def.par), add = TRUE)

par(cex = plot.settings[["cex"]])

Expand Down
4 changes: 2 additions & 2 deletions R/analyse_SAR.CWOSL.R
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ error.list <- list()
# plot everyting on one page ... doing it here is much cleaner than
# Plotting - one Page config -------------------------------------------------------
if(plot_onePage){
on.exit(on_exit())
on.exit(on_exit(), add = TRUE)

plot.single <- TRUE
layout(matrix(
Expand All @@ -890,7 +890,7 @@ error.list <- list()
}

if (plot.single[1] == FALSE) {
on.exit(on_exit())
on.exit(on_exit(), add = TRUE)
layout(matrix(
c(1, 1, 3, 3,
1, 1, 3, 3,
Expand Down
2 changes: 1 addition & 1 deletion R/analyse_SAR.TL.R
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ analyse_SAR.TL <- function(
# Plotting - Config -------------------------------------------------------
##grep plot parameter
par.default <- par(no.readonly = TRUE)
on.exit(par(par.default))
on.exit(par(par.default), add = TRUE)

##grep colours
col <- get("col", pos = .LuminescenceEnv)
Expand Down
2 changes: 1 addition & 1 deletion R/analyse_baSAR.R
Original file line number Diff line number Diff line change
Expand Up @@ -2250,7 +2250,7 @@ analyse_baSAR <- function(

if(!plot.single){
par(mfrow = c(1,2))
on.exit(par(mfrow = c(1,1), bg = "white", xpd = FALSE))
on.exit(par(mfrow = c(1,1), bg = "white", xpd = FALSE), add = TRUE)
}
##////////////////////////////////////////////////////////////////////////////////////////////
##DOSE RESPONSE CURVES AND Lx/Tx VALUES
Expand Down
8 changes: 4 additions & 4 deletions R/analyse_portableOSL.R
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ analyse_portableOSL <- function(
## set par -------
if(length(plot_settings$surface_value) > 1) {
par.default <- par(mfrow = c(2,2))
on.exit(par(par.default))
on.exit(par(par.default), add = TRUE)
}

## loop over surface values -------
Expand Down Expand Up @@ -342,7 +342,7 @@ analyse_portableOSL <- function(
par.default <- c(
if(exists("par.default")) par.default else NULL,
par(mar = c(4.5,4.5,4,2), xpd = FALSE))
on.exit(par(par.default))
on.exit(par(par.default), add = TRUE)

## open empty plot
plot(
Expand Down Expand Up @@ -391,7 +391,7 @@ analyse_portableOSL <- function(
## add legend
if(plot_settings$legend) {
par.default <- c(par.default, par(xpd = TRUE))
on.exit(par(par.default))
on.exit(par(par.default), add = TRUE)

col_grad <- plot_settings$col_ramp[
seq(1, length(plot_settings$col_ramp), length.out = 14)]
Expand Down Expand Up @@ -449,7 +449,7 @@ analyse_portableOSL <- function(
## mode == "profile" ---------
if (!is.null(mode[1]) && mode == "profile") {
par.old.full <- par(no.readonly = TRUE)
on.exit(par(par.old.full))
on.exit(par(par.old.full), add = TRUE)

# default: par(mar = c(5, 4, 4, 2) + 0.1) // bottom, left, top, right
par(mfrow = c(1, 7))
Expand Down
2 changes: 1 addition & 1 deletion R/calc_AverageDose.R
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ calc_AverageDose <- function(
##get change par setting and reset on exit
if(plot) {
par.default <- par()$mfrow
on.exit(par(mfrow = par.default))
on.exit(par(mfrow = par.default), add = TRUE)
par(mfrow = c(1,3))
}

Expand Down
2 changes: 1 addition & 1 deletion R/calc_Huntley2006.R
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ calc_Huntley2006 <-
}

# recover plot parameters
on.exit(par(par.old.full))
on.exit(par(par.old.full), add = TRUE)

}

Expand Down
2 changes: 1 addition & 1 deletion R/calc_gSGC_feldspar.R
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ calc_gSGC_feldspar <- function (
# Plotting ----------------------------------------------------------------
if(plot){
old.par <- par(no.readonly = TRUE)
on.exit(par(old.par))
on.exit(par(old.par), add = TRUE)

par(mfrow = c(mfrow = c(3,3)))
for (i in 1:length(l)) {
Expand Down
6 changes: 3 additions & 3 deletions R/combine_De_Dr.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
),
val = method_control)

on.exit(close(model))
on.exit(close(model), add = TRUE)
## select model
if(length(theta) == 1) {
data1$theta <- NULL
Expand Down Expand Up @@ -268,7 +268,7 @@
),
val = method_control)

on.exit(close(model))
on.exit(close(model), add = TRUE)
data <-
list(
'theta' = theta,
Expand Down Expand Up @@ -712,7 +712,7 @@ if(plot){
##make sure we reset plots
if(par_local) {
old.par <- par(mfrow = c(1, 2))
on.exit(par(old.par))
on.exit(par(old.par), add = TRUE)

}

Expand Down
2 changes: 1 addition & 1 deletion R/fit_EmissionSpectra.R
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ fit_EmissionSpectra <- function(

if(!is.na(fit[1]) && class(fit)[1] != "try-error"){
##make sure that the screen closes if something is wrong
on.exit(close.screen(n = c(1,2)))
on.exit(close.screen(n = c(1,2)), add = TRUE)

##set split screen settings
split.screen(rbind(
Expand Down
2 changes: 1 addition & 1 deletion R/fit_LMCurve.R
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ fit_LMCurve<- function(

# layout safety settings
par.default <- par()[c("mfrow", "cex", "mar", "omi", "oma")]
on.exit(par(par.default))
on.exit(par(par.default), add = TRUE)

##============================================================================##
## BACKGROUND SUBTRACTION
Expand Down
2 changes: 1 addition & 1 deletion R/fit_OSLLifeTimes.R
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ if(plot) {

if(!plot_simple){
##make sure that the screen closes if something is wrong
on.exit(close.screen(all.screens = TRUE))
on.exit(close.screen(all.screens = TRUE), add = TRUE)

split.screen(rbind(
c(0.1,1,0.32, 0.98),
Expand Down
2 changes: 1 addition & 1 deletion R/plot_AbanicoPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ plot_AbanicoPlot <- function(

## this ensures par() is respected for several plots on one page
if(sum(par()$mfrow) == 2 & sum(par()$mfcol) == 2){
on.exit(par(par.old.full))
on.exit(par(par.old.full), add = TRUE)
}

## check/set layout definitions
Expand Down
2 changes: 1 addition & 1 deletion R/plot_DRTResults.R
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ plot_DRTResults <- function(
if (shift.lines <= 0)
shift.lines <- 1
par.default <- par(mfrow = c(1, 1), cex = cex, oma = c(0, 1, shift.lines - 1, 1))
on.exit(par(par.default))
on.exit(par(par.default), add = TRUE)
}

## optionally plot values and error bars
Expand Down
2 changes: 1 addition & 1 deletion R/plot_FilterCombinations.R
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ plot_FilterCombinations <- function(
)

print(p)
on.exit(return(p))
on.exit(return(p), add = TRUE)


}else{
Expand Down
2 changes: 1 addition & 1 deletion R/plot_GrowthCurve.R
Original file line number Diff line number Diff line change
Expand Up @@ -1915,7 +1915,7 @@ plot_GrowthCurve <- function(

## safe par settings
par.old.full <- par(no.readonly = TRUE)
on.exit(par(par.old.full))
on.exit(par(par.old.full), add = TRUE)

##set new parameter
layout(matrix(c(1, 1, 1, 1, 2, 3), 3, 2, byrow = TRUE), respect = TRUE)
Expand Down
3 changes: 1 addition & 2 deletions R/plot_RLum.Analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,11 @@ plot_RLum.Analysis <- function(

##set par
par.default <- par("mfrow")
if(!plot.single){on.exit(par(mfrow = par.default))}
if(!plot.single) {
par(mfrow = c(nrows, ncols))
on.exit(par(mfrow = par.default), add = TRUE)
}


##expand plot settings list
plot.settings <- lapply(setNames(1:length(plot.settings), names(plot.settings)),
function(x) {
Expand Down
4 changes: 2 additions & 2 deletions R/plot_RLum.Data.Image.R
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ plot_settings <- modifyList(x = list(
# plot.raster -------------------------------------------------------------
for(i in 1:dim(object)[3]) {
par.default <- par(mar = c(4.5,4.5,4,3))
on.exit(par(par.default))
on.exit(par(par.default), add = TRUE)
x <- object[, , i, drop = FALSE]
image <-.stretch(x, type = plot_settings$stretch)

Expand Down Expand Up @@ -180,7 +180,7 @@ plot_settings <- modifyList(x = list(
## add legend
if(plot_settings$legend) {
par.default <- c(par.default, par(xpd = TRUE))
on.exit(par(par.default))
on.exit(par(par.default), add = TRUE)
col_grad <- plot_settings$col[seq(1, length(plot_settings$col), length.out = 14)]
slices <- seq(0,1,length.out = 15)
for(s in 1:(length(slices) - 1)){
Expand Down
2 changes: 1 addition & 1 deletion R/plot_RLum.Data.Spectrum.R
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ if(plot){
)

print(p)
on.exit(return(p))
on.exit(return(p), add = TRUE)


}else if(plot.type == "contour" && ncol(temp.xyz) > 1) {
Expand Down
4 changes: 2 additions & 2 deletions R/plot_RLum.Results.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ plot_RLum.Results<- function(
## SAFE AND RESTORE PLOT PARAMETERS ON EXIT
##============================================================================##
par.old <- par(no.readonly = TRUE)
on.exit(suppressWarnings(par(par.old)))
on.exit(suppressWarnings(par(par.old)), add = TRUE)

##============================================================================##
## ... ARGUMENTS
Expand Down Expand Up @@ -1022,7 +1022,7 @@ plot_RLum.Results<- function(
par(bty="n")
boxplot(MC.n, horizontal = TRUE, add = TRUE, bty="n")
} else {
on.exit(NULL)
on.exit(NULL, add = TRUE) # FIXME(mcol): seems unnecessary
}
}#EndOf::Case 5 - calc_AliqoutSize()

Expand Down
2 changes: 1 addition & 1 deletion R/plot_RadialPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,7 @@ label.text[[1]] <- NULL
cex = cex)

## reset on exit
on.exit(par(default))
on.exit(par(default), add = TRUE)

## create empty plot
plot(NA,
Expand Down
2 changes: 1 addition & 1 deletion R/read_BIN2R.R
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ read_BIN2R <- function(
close(con)
}
}
on.exit(expr = on_exit())
on.exit(expr = on_exit(), add = TRUE)

## check for URL and attempt download
if(verbose)
Expand Down
2 changes: 1 addition & 1 deletion R/read_Daybreak2R.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ read_Daybreak2R <- function(
if(substr(file, start = nchar(file) - 3, stop = nchar(file)) == ".DAT"){

# Read DAT-file ------------------------------------------------------------------------------
on.exit(close(con))
on.exit(close(con), add = TRUE)

##screen file to get information on the number of stored records
con<-file(file,"rb")
Expand Down
2 changes: 1 addition & 1 deletion R/scale_GammaDose.R
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ scale_GammaDose <- function(

# save and recover plot parameters
par.old <- par(no.readonly = TRUE)
on.exit(par(par.old))
on.exit(par(par.old), add = TRUE)

if (plot_single)
layout(matrix(c(1,1, 2, 3, 4, 5,
Expand Down
2 changes: 1 addition & 1 deletion R/use_DRAC.R
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ use_DRAC <- function(
reply <- readline("Do you want to see the DRAC error message (Y/N)?")
if (reply == "Y" || reply == "y" || reply == 1)
cat(error_msg)
})
}, add = TRUE)
# nocov end

.throw_error("\n\t We got a response from the server, but it\n",
Expand Down

0 comments on commit c9834f9

Please sign in to comment.