





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






log (-1) Warning in log (-1): NaNs produced [ 1 ] NaN
printmessage2( NA ) [ 1 ] "x is a missing value!"
x <- log ( c (-1, 2 )) Warning in log ( c (-1, 2 )): NaNs produced printmessage2(x) Warning in if ( is.na (x)) print ("x is a missing value!") else if (x > 0) print ("x is greater than zero") else print ("x is less than or equal to zero"): the condition has length > 1 and only the first element will be used [ 1 ] "x is a missing value!"
printmessage3 <- function (x) {
printmessage3(1:2) Error in printmessage3(1:2): 'x' has length > 1
printmessage4 <- Vectorize (printmessage2) out <- printmessage4( c (-1, 2 )) [ 1 ] "x is less than or equal to zero" [ 1 ] "x is greater than zero"
20.2 Figuring Out What’s Wrong
20.3 Debugging Tools in R
lm(y ~ x) Error in eval (expr, envir, enclos) : object ’y’ not found traceback () 7: eval (expr, envir, enclos) 6: eval (predvars, data, env) 5: model.frame.default(formula = y ~ x, drop.unused.levels = TRUE ) 4: model.frame(formula = y ~ x, drop.unused.levels = TRUE ) 3: eval (expr, envir, enclos) 2: eval (mf, parent.frame ()) 1: lm(y ~ x)
20.5 Using debug()
debug (lm) ## Flag the 'lm()' function for interactive debugging lm(y ~ x) debugging in : lm(y ~ x) debug : { ret.x <- x ret.y <- y cl <- match.call () ... if (! qr ) z$qr <- NULL z } Browse[ 2 ]>
Browse[ 2 ]> n ## Evalute this expression and move to the next one debug : ret.x <- x Browse[ 2 ]> n debug : ret.y <- y Browse[ 2 ]> n debug : cl <- match.call () Browse[ 2 ]> n debug : mf <- match.call (expand.dots = FALSE ) Browse[ 2 ]> n debug : m <- match ( c ("formula", "data", "subset", "weights", "na.action", "offset"), names (mf), 0L)
undebug (lm) ## Unflag the 'lm()' function for debugging
20.6 Using recover()