Thanks jeff,

You are right about my expectation so if you have time please take a look
at this:

library(spdep)

test <- function () {
#read neighborhood list
  neigh.gal <- read.gal("
http://sites.google.com/site/geosciej/Home/ter1RIorigM_T1.GAL?revision=1";)

#Making a weight matrix (listW)
  w <- nb2listw(neigh.gal,style="B", zero.policy=TRUE)

  sink("w.txt")
  summary(w)
  sink()
#Did the execution reached this point?
  print("the function reached this point in the code")

}


and the result would be:

> test()
Error in print(data.frame(rbind(unlist(spweights.constants(object,
zero.policy = zero.policy))[c(1,  :
  error in evaluating the argument 'x' in selecting a method for function
'print': Error in spweights.constants(object, zero.policy = zero.policy) :
  regions with no neighbours found

obviously the function does not go beyod sink().

the problem is at the print stage. the function does the job and this error
is expected but still it halts the execution of function running (and the
problem is not the sink() function, I tried).

I tried

try(test())
options(showErrorCalls=F)
options(show.error.messages=F)

for tryCatch() I could put the whole other part of the function in the
"finally" argument but it is not practical with many lines of code ahead.

I expect the code to continue executing regardless of any error or warning.

appreciate it

Ebrahim




On Tue, Apr 3, 2012 at 5:45 AM, Jeff Newmiller <[email protected]>wrote:

> Sounds like you tried everything I know. However, I, and anyone else on
> this list whose mind-reading powers are undeveloped, really can't be sure
> because you didn't show us what you tried. Perhaps you should (re-)read the
> posting guidelines and try showing us reproducible sample code that doesn't
> do what you expect it to (along with some indication of what you expected
> it to do).
> ---------------------------------------------------------------------------
> Jeff Newmiller                        The     .....       .....  Go Live...
> DCN:<[email protected]>        Basics: ##.#.       ##.#.  Live
> Go...
>                                      Live:   OO#.. Dead: OO#..  Playing
> Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
> /Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
> ---------------------------------------------------------------------------
> Sent from my phone. Please excuse my brevity.
>
> Ebrahim Jahanshiri <[email protected]> wrote:
>
> >Dear all,
> >
> >I have written some function that can go up to many lines. Two of the
> >lines
> >give warning errors like:
> >
> >Error in print(....)[c(1,  :
> >  error in evaluating the argument 'x' in selecting a method for
> >function 'print': Error in ...
> >  regions with no neighbours found
> >
> >
> >now obviously this kind of error will halt the execution of the
> >function. I
> >tried *try()* or *tryCatch()* and many other selections in the
> >*options()*but still this error by all means stops the execution of
> >the function or
> >any other multi-line code.
> >
> >I would appreciate if you could give me a clue.
> >
> >Ebrahim
> >
> >       [[alternative HTML version deleted]]
> >
> >______________________________________________
> >[email protected] 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.
>
>

        [[alternative HTML version deleted]]

______________________________________________
[email protected] 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