Look at what sapply() is returning before you assign it into zest[i]. If the return value has length 0, set zest[i] to NA. If it has length more than 1, I don't know what you want to do. If it has length 1 then do the assignment.
zest <- numeric(1) tmp <- tryCatch(sapply(...), error=function()NA) if (length(tmp)==1) { zest[i] <- tmp } else if (length(tmp)==0) { zest[i] <- NA } else { warning("length from sapply is ", length(tmp), ", what should I do?") } If zest is a list you may want to be using zest[[i]] <- tryCatch(sapply(...)). Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -----Original Message----- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of eric > Sent: Sunday, July 10, 2011 12:38 PM > To: r-help@r-project.org > Subject: Re: [R] Help with tryCatch > > I tried the following: > > zest[i] <- tryCatch(sapply(getNodeSet(zdoc, "//zestimate/amount"), > xmlValue), error=function() NA) > > Here's what happens : > > Error in zest[i] <- tryCatch(sapply(getNodeSet(zdoc, > "//zestimate/amount"), > : > replacement has length zero > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Help-with-tryCatch-tp3657859p365 8113.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.