[R] tryCatch question
Antje
niederlein-rstat at yahoo.de
Fri Sep 12 15:02:36 CEST 2008
Hi there,
I have a nested call of lapply in which I do a tryCatch statement like this
lapply(1:length(p_names), function(w_idx) {
r <- as.numeric(pos_r[[w_idx]][1])
c <- as.numeric(pos_c[[w_idx]][1])
pos <- c(r,c)
lapply(1:length(p_names[[w_idx]]), function(p_idx, pos) {
parameter <- p_names[[w_idx]][[p_idx]]
value <- p_vals[[w_idx]][[p_idx]]
tryCatch({ as.numeric(value) }, warning = function(ex) { value})
oad$resultValues[[parameter]][pos[1],pos[2]] <<- value
NULL
}, pos)
})
(sorry, that I don't have a simple test code here...)
the tryCatch shall convert a value in a number if this makes sense (so "3.3"
should be converted, but not "hello"; all values are strings)
if I simply execute something like this:
value <- "3.3"
tryCatch({ as.numeric(value) }, warning = function(ex) { value})
it works pretty nice. but within the lapply construct I always end up with strings.
Does anybody have an idea why? (I can try to create a simple testcode for this
but maybe there is already someone who knows what's wrong?
Ciao,
Antje
More information about the R-help
mailing list