having trouble handling errors in loop because of scope in trycatch error function, imagine.
the error handles correctly in sense skips , continues working, whats in error function doesn't write data frame (d), when error ocurrs, output number of row, instead of nulls or na's.
what missing? visual example of loops taking place.
function<-function(vector){ n<-length(vector) d<-data.frame(a=1:n, b=1:n, c=1:n) (i in 1:n) { trycatch({ #create m every in vector m<-foo(i) (j in 1:length(m[,1])) { #for every element in m, transform function m[j]<-foo2(j) } #now, m transformed, fill every element of d (so matches elements of vector) d[i,]$a = sum(m) d[i,]$b = sd(m) d[i,]$c = mean(m) #end try }, error = function(e){ #if there erorr in m<-foo(i), want place null or na values in each column of d d[i,]$a = null d[i,]$b = null d[i,]$c = null } #end trycatch ) #end loop } #end function }
Comments
Post a Comment