GEOquery: How to use the tryCatch
1
0
Entering edit mode
r.b.li • 0
@rbli-7122
Last seen 10.1 years ago
China

I have written an R script which includes a loop to download a list of Gsm. However, the url of some Gsms have changed or the condition internet became bad temporarily leading to a break of loop.

I want to continue the loop if some gsms fail to download and the name of gsm is written in a new list.

Then robert advise me the tryCatch function link to C: Geoquery: How to Continue Code Execution on Error

However, i fail to complete the second goal that recording the gsm with warning or error.

My cold is listed below and anyone could help me?

testlist=c("GSMxxx")# There is not a GSMxxx
errorrecord=c()
warningrecord=c()
acc <- testlist[1]
address <- "e:/lab/bigdata/originaldata/sample/test/"
tryCatch(getGEOfile(acc, destdir = address, AnnotGPL = F,amount=c("data")),
         warnings=function(war){warningrecord=append(warningrecord,acc)},
         error=function(err){errorrecord=append(errorrecord,acc)}
         )

Thanks a lot!

r trycatch geoquery • 1.4k views
ADD COMMENT
0
Entering edit mode
Robert Castelo ★ 3.4k
@rcastelo
Last seen 6 days ago
Barcelona/Universitat Pompeu Fabra

Hi Robin,

there was no need to open a new question, you could simply reply on the same one you first posted. Anyway, for what you ask now I think you could simply return what you are interested to store. The problem you have right now is related to the scope of the variables. Concretely, 'warningrecord' and 'errorecord' within the functions are different variables from the ones defined outside these functions. The solution I'm talking about would be this:

rec <- tryCatch(getGEOfile(acc, destdir = address, AnnotGPL = F,amount=c("data")),
                           warnings=function(war){ acc },
                           error=function(err) { acc })
rec
[1] "GSMxxx"

cheers,

robert.

ADD COMMENT
0
Entering edit mode

Deer Robert.

Thanks a lot again. I can not believe that it is also your help guiding me out of the mess.

I am truly feeling frantic about the problem of software sometimes. A little month ago, I did not know what was R and bioconductor!

Could I get your e-mail or any contacts if you are convenient? And my e-mail is r.b.li@foxmail.com. :)

Best regards!

Robin

Nanjing, China

 

ADD REPLY

Login before adding your answer.

Traffic: 448 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6