[R] un run run...

jim holtman jholtman at gmail.com
Fri Aug 14 15:33:51 CEST 2009


If you really want to skip to the next line on an error without
checking, then wrap each line in 'try', or put blocks in a try:

try(...expr...)
try(...expr...)
try({
    ....expr...
    ....expr....
    ....expr....
})



On Fri, Aug 14, 2009 at 8:51 AM, Nir Shachaf<nirshachaf at gmail.com> wrote:
> Thanks again for your reply, Thierry.
>
> Packing several functions into another function
> would again seem to create a nested structure
> (only slightly smaller).
>
> The simplest solution would be to use [R]'s parsing
> or evaluation commands to skip to the next line
> once a certain function returns an error
>
> All the best,
> Nir
>
> On Thu, Aug 13, 2009 at 1:07 PM, ONKELINX,
> Thierry<Thierry.ONKELINX at inbo.ber > wrote:
>> It depends on how you want to deal with errors. If you need to do some depeding on the function that throws an error then you need a nested structure. Otherwise you can wrap all the functions in a big function an try() that function.
>>
>> Big_function <- function(some params, ...){
>>        s1 <- func1(some params)         # can generate errors
>>        s2 <- func2(s1,...)  # yes she can aswell
>>        s3 <- func3(s2,...)  # same here
>> }
>>
>> try(Big_function(parameters))
>>
>> HTH,
>>
>> Thierry
>>
>> PS Please include the mailing list in your replies.
>>
>> ----------------------------------------------------------------------------
>> ir. Thierry Onkelinx
>> Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest
>> Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance
>> Gaverstraat 4
>> 9500 Geraardsbergen
>> Belgium
>> tel. + 32 54/436 185
>> Thierry.Onkelinx at inbo.be
>> www.inbo.be
>>
>> To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of.
>> ~ Sir Ronald Aylmer Fisher
>>
>> The plural of anecdote is not data.
>> ~ Roger Brinner
>>
>> The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data.
>> ~ John Tukey
>>
>> -----Oorspronkelijk bericht-----
>> Van: Nir Shachaf [mailto:nirshachaf at gmail.com]
>> Verzonden: donderdag 13 augustus 2009 11:37
>> Aan: ONKELINX, Thierry
>> Onderwerp: Re: [R] un run run...
>>
>> Thierry hi,
>>
>> Most grateful for your detailed reply.
>>
>> The specific conditions that I am working with are that every function that I call can generate an unexpected error: So that using your solution would result in nested "if - then" statements...
>>
>> My data looks similar to this:
>>
>> s1 <- func1(some params)         # can generate errors
>> s2 <- func2(s1,...)  # yes she can aswell
>> s3 <- func3(s2,...)  # same here
>> ...
>>
>> then the whole thing repeats with diffrent parameters ...
>>
>> etc.
>>
>>
>> Ideally, I would have set "options(error = expression("some command"))" and have "some command" advance the execution pointer of "source" by one step, which would eventually get me to a working line and continue script run.
>>
>> Any hint?
>>
>> Thanks once more,
>> Nir
>>
>> On Thu, Aug 13, 2009 at 12:13 PM, ONKELINX, Thierry<Thierry.ONKELINX at inbo.be> wrote:
>>> Here is an example in pseudo code.
>>>
>>> Instead of
>>>
>>> Object <- function that can generate error Other things to do
>>>
>>> Do something like
>>>
>>> Object <- try(function that can generate error)
>>> if(class(Object) == "try-error"){
>>>        things to do when an error occures } else {
>>>        other things to do
>>> }
>>>
>>> HTH,
>>>
>>> Thierry
>>>
>>> ----------------------------------------------------------------------
>>> --
>>> ----
>>> ir. Thierry Onkelinx
>>> Instituut voor natuur- en bosonderzoek / Research Institute for Nature
>>> and Forest Cel biometrie, methodologie en kwaliteitszorg / Section
>>> biometrics, methodology and quality assurance Gaverstraat 4 9500
>>> Geraardsbergen Belgium tel. + 32 54/436 185 Thierry.Onkelinx at inbo.be
>>> www.inbo.be
>>>
>>> To call in the statistician after the experiment is done may be no
>>> more than asking him to perform a post-mortem examination: he may be
>>> able to say what the experiment died of.
>>> ~ Sir Ronald Aylmer Fisher
>>>
>>> The plural of anecdote is not data.
>>> ~ Roger Brinner
>>>
>>> The combination of some data and an aching desire for an answer does
>>> not ensure that a reasonable answer can be extracted from a given body
>>> of data.
>>> ~ John Tukey
>>>
>>> -----Oorspronkelijk bericht-----
>>> Van: r-help-bounces at r-project.org
>>> [mailto:r-help-bounces at r-project.org]
>>> Namens Nir Shachaf
>>> Verzonden: donderdag 13 augustus 2009 11:00
>>> Aan: r-help at r-project.org
>>> Onderwerp: [R] un run run...
>>>
>>> Hi All,
>>>
>>> I am running an Rscript with a bunch of algorithms that are UNSTABLE
>>> under some parameter settings.
>>>
>>> At a certain point one of them sends error massage and my whole run
>>> STOPS!
>>>
>>> What I would like is to save the error massage in some file or
>>> variable and carry on to the next command line without stopping this run...
>>>
>>> Any help or ideas would be welcome, please, with a concrete example
>>> (not just - "have you thought of using 'tryCatch' etc.).
>>>
>>> Thanks all!
>>> Nir
>>>
>>> ______________________________________________
>>> R-help at 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.
>>>
>>> Dit bericht en eventuele bijlagen geven enkel de visie van de
>>> schrijver weer en binden het INBO onder geen enkel beding, zolang dit
>>> bericht niet bevestigd is door een geldig ondertekend document. The
>>> views expressed in  this message and any annex are purely those of the
>>> writer and may not be regarded as stating an official position of
>>> INBO, as long as the message is not confirmed by a duly signed document.
>>>
>>
>> Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer
>> en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is
>> door een geldig ondertekend document. The views expressed in  this message
>> and any annex are purely those of the writer and may not be regarded as stating
>> an official position of INBO, as long as the message is not confirmed by a duly
>> signed document.
>>
>
> ______________________________________________
> R-help at 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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?




More information about the R-help mailing list