การเขียน R แบบ Defensive Programming
Dr. Colin Gillespie
Jumping Rivers
ฟังก์ชัน warning()
warning("You have been warned!")
# Warning message:
# You have been warned!
คล้ายกับข้อความทั่วไป สามารถยับยั้งคำเตือนได้ด้วย
suppressWarnings()`แทบไม่เคยเป็นความคิดที่ดีเลย

Photo by Austin Chan
สมมติว่ากำลังทำ regression กับข้อมูลต่อไปนี้
d = data.frame(y = 1:4, x1 = 1:4)
d$x2 = d$x1 + 1
ดังนั้น x2 = x1 + 1
เมื่อ fit โมเดล multiple linear regression
m = lm(y ~ x1 + x2, data = d)
summary(m)
# Some output removed
# Warning message:
# In summary.lm(m) : essentially perfect fit: summary may be unreliable
การเขียน R แบบ Defensive Programming