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

______________________________________________
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.

Reply via email to