1- # Package Environment
2- .errorist_env = new.env()
3-
41# ' Enable or Disable Errorist's Automatic Search
52# '
63# ' Activates or disengages the automatic look up of error or warning codes in
@@ -156,6 +153,12 @@ enable_warning_shim = function(warning_search_func =
156153 # No warning messages yet (we hope!)
157154 .errorist_env $ captured_last_search_warning = NA
158155
156+ # Restore to default setting to ensure `last.warning` is created.
157+ warn_level = getOption(" warn" , 0 )
158+ if (warn_level != 0 ) {
159+ options(" warn" = 0 )
160+ }
161+
159162 # Automatically call the warning_handler after each R function is run
160163 handler = addTaskCallback(warning_handler(warning_search_func ),
161164 name = " ErroristWarningHandler" )
@@ -168,6 +171,9 @@ disable_warning_shim = function() {
168171 # Reset the warning
169172 .errorist_env $ captured_last_search_warning = NULL
170173
174+ # Restore original warning level
175+ options(" warn" = .errorist_env $ warn_level )
176+
171177 # Remove handler
172178 removed_handler = removeTaskCallback(" ErroristWarningHandler" )
173179}
@@ -197,9 +203,6 @@ enable_error_shim = function(error_search_func =
197203 # Remove the shim if it exists...
198204 disable_error_shim()
199205
200- # Save present options
201- .errorist_env $ op = options()
202-
203206 # Errorist
204207 op.errorist = list (error = error_search_func )
205208
@@ -210,17 +213,13 @@ enable_error_shim = function(error_search_func =
210213# ' @rdname shims
211214# ' @export
212215disable_error_shim = function () {
213- # Restore options
214- if (exists(" op" , envir = .errorist_env ) &&
215- is.null(.errorist_env $ op )) {
216- # Empty if condition...
217216
218- } else if (" error" %in% names(.errorist_env $ op )) {
217+ # Restore options
218+ if (" error" %in% names(.errorist_env $ op )) {
219219 options(.errorist_env $ op )
220220 } else {
221221 # Ensure error is nullified.
222222 options(error = NULL )
223223 }
224224
225- .errorist_env $ op = NULL
226225}
0 commit comments