--5-Robust functions
# Three main problems:
# type unstable functions
# non standard evaluation
# hidden argument# Add a call to stopifnot() to both_na() that checks arguments x and
# y have the same length.
# Run the call to both_na() to verify it returns an error.
# Define troublesome x and y
x <- c(NA, NA, NA)
y <- c( 1, NA, NA, NA)
both_na <- function(x, y) {
# Add stopifnot() to check length of x and y
stopifnot(length(x)==length(y))
sum(is.na(x) & is.na(y))
}
# Call both_na() on x and y
both_na(x, y)Last updated