Using R's tryCatch
<p>Trying to use <code>R</code>'s <code>tryCatch</code> on fitting a log-logistic curve to a dose-response data:</p>

<pre><code>df &lt;- data.frame(dose=c(10,0.62,2.5,0.16,0.039,0.0024,0.0098,0.00061,10,0.62,2.5,0.16,0.039,0.0024,0.0098,0.00061,10,0.62,2.5,0.16,0.039,0.0024,0.0098,0.00061),
                 viability=c(22,79,100,61,100,87,75,51,6.5,37,100,100,90,100,42,41,5,100,13,100,91,100,95,100),
                 stringsAsFactors = F)
</code></pre>

<p>with <code>drc</code>'s <code>drm</code> function using this code:</p>

<pre><code>library(drc)
fit &lt;- tryCatch(
  {
    drm(viability~dose,data=df,fct=LL.4(names=c("slope","low","high","ED50")))
  },
  error=function(cond){
    return(NA)
  },
  warning=function(cond){
    return(NA)
  },
  finally={  
  }
)
</code></pre>

<p>I get:</p>

<pre><code>&gt; fit
[1] NA
</code></pre>

<p>However, when I try without <code>tryCatch</code> there's no problem:</p>

<pre><code>&gt; drm(viability~dose,data=df,fct=LL.4(names=c("slope","low","high","ED50")))

A 'drc' model.

Call:
drm(formula = viability ~ dose, data = df, fct = LL.4(names = c("slope",     "low", "high", "ED50")))

Coefficients:
slope:(Intercept)    low:(Intercept)   high:(Intercept)   ED50:(Intercept)  
            1.498           -163.577             81.031             18.481  
</code></pre>

<p>Am I not using <code>tryCatch</code> correctly?</p>