title: Return integer using TclTK from C library
body: <p>I have C code that uses Tcl/Tk library. I then create a library using this C code which is then linked to R language package. I have a function in the C code:</p>
  <pre><code>int doSomething(){
     if(TRUE){
        return TCL_OK;
     else{
        TCL_RESULT3(&quot;Error&quot;)
        return TCL_OK;
  }
  </code></pre>
  <p>Currently, I use <code>TCL_RESULT3(&quot;Error&quot;)</code> in the C code, and then in R check if <code>result &lt;- tclvalue(tcl(...)) #calls doSomething()</code> returns a string with <code>Error</code>:</p>
  <pre><code>if (startsWith(result, &quot;Error&quot;))
          {
              return(FALSE)
          }
          return(TRUE)
  </code></pre>
  <p>and base further actions in R on the returned value.</p>
  <p>However, even though there is an error, I still call <code>TCL_OK</code> because <code>TCL_ERROR</code> produces something that R cannot seem to handle (at least it is not straightforward). My question is if it is possible to restructure my function as:</p>
  <pre><code>int doSomething(){
     if(TRUE){
        return TCL_OK;
     else{
        return TCL_ERROR;
  }
  </code></pre>
  <p>and have R understand what is being returned. Currently, if <code>TCL_OK</code> is returned, then <code>result</code> will be an empty string <code>&quot;&quot;</code>. If <code>TCL_ERROR</code> is returned, then result will yield: <code>Error in structure(.External(.C_dotTclObjv, objv), class = &quot;tclObj&quot;) : [tcl] .</code> which R does not know how to handle.</p>
  <p>Is it possible to have R handle such an error (i.e. return a value of FALSE if this error pops up) or is checking for an error message using <code>TCL_RESULT3()</code> in conjunction with <code>TCL_OK</code> the best method for such a process?</p>