ID EN
Vector & List

conditions

R Base 3.6.2 🇮🇩 Bahasa Indonesia

Fungsi-fungsi ini menyediakan mekanisme untuk menangani kondisi yang tidak biasa, termasuk kesalahan dan peringatan.

Syntax

R
tryCatch(expr, …, finally)
withCallingHandlers(expr, &#8230;)<p></p><p>signalCondition(cond)</p><p>simpleCondition(message, call = NULL)
simpleError    (message, call = NULL)
simpleWarning  (message, call = NULL)
simpleMessage  (message, call = NULL)</p><p>errorCondition(message, ..., class = NULL, call = NULL)
warningCondition(message, ..., class = NULL, call = NULL)</p><p># S3 method for condition
as.character(x, &#8230;)
# S3 method for error
as.character(x, &#8230;)
# S3 method for condition
print(x, &#8230;)
# S3 method for restart
print(x, &#8230;)</p><p>conditionCall(c)
# S3 method for condition
conditionCall(c)
conditionMessage(c)
# S3 method for condition
conditionMessage(c)</p><p>withRestarts(expr, &#8230;)</p><p>computeRestarts(cond = NULL)
findRestart(name, cond = NULL)
invokeRestart(r, &#8230;)
invokeRestartInteractively(r)</p><p>isRestart(x)
restartDescription(r)
restartFormals(r)</p><p>suspendInterrupts(expr)
allowInterrupts(expr)</p><p>.signalSimpleWarning(msg, call)
.handleSimpleError(h, msg, call)
.tryResumeInterrupt()</p>

Arguments

Parameter Deskripsi
c a condition object.
call call expression.
cond a condition object.
expr expression to be evaluated.
finally expression to be evaluated before returning or exiting.
h function.
message character string.
msg character string.
name character string naming a restart.
r restart object.
x object.
class character string naming a condition class.
&#8230; additional arguments; see details below.

Details

Sistem kondisi menyediakan mekanisme untuk memberi sinyal dan menangani kondisi yang tidak biasa, termasuk kesalahan dan peringatan. Kondisi direpresentasikan sebagai objek yang berisi informasi tentang kondisi yang terjadi, misalnya pesan dan panggilan di mana kondisi tersebut terjadi. Saat ini kondisinya adalah objek bergaya S3, meskipun hal ini pada akhirnya dapat berubah. Kondisi adalah objek yang mewarisi kondisi kelas abstrak. Kesalahan dan peringatan adalah objek yang diwarisi dari subkelas abstrak kesalahan dan peringatan. Kelas simpleError adalah kelas yang digunakan oleh stop dan semua sinyal kesalahan internal. Demikian pula, simpleWarning digunakan oleh peringatan, dan simpleMessage digunakan oleh pesan. Konstruktor dengan nama yang sama mengambil string yang mendeskripsikan kondisi sebagai argumen dan panggilan opsional. Fungsinya

Contoh

Example
R
# NOT RUN {
tryCatch(1, finally = print("Hello"))
e <- simpleError("test error")
# }
# NOT RUN {
 stop(e)
 tryCatch(stop(e), finally = print("Hello"))
 tryCatch(stop("fred"), finally = print("Hello"))
# }
# NOT RUN {
tryCatch(stop(e), error = function(e) e, finally = print("Hello"))
tryCatch(stop("fred"),  error = function(e) e, finally = print("Hello"))
withCallingHandlers({ warning("A"); 1+2 }, warning = function(w) {})
# }
# NOT RUN {
 { withRestarts(stop("A"), abort = function() {}); 1 }
# }
# NOT RUN {
withRestarts(invokeRestart("foo", 1, 2), foo = function(x, y) {x + y})

##--> More examples are part of
##-->   demo(error.catching)
# }

See Also

stop and warning signal conditions and try is essentially a simplified version of tryCatch. assertCondition in package tools tests that conditions are signalled and works with several of the above handlers.