r - Abruptly stop executing a command and continue to the next one -


i have set of files on need apply rpart algorithm. of these files takes long computation. how can skip such cases (eg. cases take more hour) , continue on next one?

for (i in num) { print(i) infilename  = filenames[i] tmpdata = read.table(infilename, header = true,  sep= "\t") retval = rpart(fmla[i],  dat=tmpdata, method = "class") print (retval) } 

edit: based on suggestin @dwin, doing following not work. doing wrong?

for (i in num) { print(i) infilename  = filenames[i] tmpdata = read.table(infilename, header = true,  sep= "\t") retval= null settimelimit(cpu=10) retval = try(rpart(fmla,  dat=tmpdata, method = "class") ) print (retval) } 

because using regular r functions (and not coding scratch), need come way estimate conditions leading excessive times. might test looks @ dimensions of dataframe , skips next rpart computation if product of dim(dfrm) exceeds threshold.

retval = if(prod(dim(tmpdata)) < 1e6) {                 rpart(fmla[i],  dat=tmpdata, method = "class") } 

notice @ moment overwriting retval every loop iteration rather storing durable object.

you try using functions settimelimit , setsessionlimit these throw error condition , may need put code inside try function recover gracefully:

 settimelimit(cpu=2) (i in 4:8) {x <- 1:10^i;x=x^3}  max(x) #[1] 1e+24 # did not exceed limits x^(1/3) #[1]     1     2     3     4     5     6     7error: reached cpu time limit 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -