Skip to content

Commit fd74906

Browse files
committed
When plot = FALSE, don't call plot.new
plot.new() is generally unfriendly to call unless it will actually be used for drawing, and certainly not if we ask for no plots to be created. plot.new triggers the completion of the previous plotting action, and as such can't be used in combination with any multithreading or forked R processes. plot.new also does not return a "plot" object, it always returns `NULL`, so although it appears to be used here as a way of returning a "null plot", all that really happens is that AnomalyDetection* returns `list(..., plot = NULL)`. This commit resolves twitter#60
1 parent 1f5deaa commit fd74906

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

R/ts_anom_detection.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ AnomalyDetectionTs <- function(x, max_anoms = 0.10, direction = 'pos',
297297
# If there are no anoms, then let's exit
298298
if(anom_pct == 0){
299299
if(verbose) message("No anomalies detected.")
300-
return (list("anoms"=data.frame(), "plot"=plot.new()))
300+
return (list("anoms"=data.frame(), "plot"=NULL))
301301
}
302302

303303
if(plot){
@@ -359,6 +359,6 @@ AnomalyDetectionTs <- function(x, max_anoms = 0.10, direction = 'pos',
359359
if(plot){
360360
return (list(anoms = anoms, plot = xgraph))
361361
} else {
362-
return (list(anoms = anoms, plot = plot.new()))
362+
return (list(anoms = anoms, plot = NULL))
363363
}
364364
}

R/vec_anom_detection.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ AnomalyDetectionVec = function(x, max_anoms=0.10, direction='pos',
224224
# If there are no anoms, then let's exit
225225
if(anom_pct == 0){
226226
if(verbose) message("No anomalies detected.")
227-
return (list("anoms"=data.frame(), "plot"=plot.new()))
227+
return (list("anoms"=data.frame(), "plot"=NULL))
228228
}
229229

230230
if(plot){
@@ -287,6 +287,6 @@ AnomalyDetectionVec = function(x, max_anoms=0.10, direction='pos',
287287
if(plot){
288288
return (list(anoms = anoms, plot = xgraph))
289289
} else {
290-
return (list(anoms = anoms, plot = plot.new()))
290+
return (list(anoms = anoms, plot = NULL))
291291
}
292292
}

0 commit comments

Comments
 (0)