title: What is the R equivalent of Matlab's fminunc function?
body: <p>In order to compute the optimal theta e.g. in logistic regression, I have to create a costFunction (the function to be minimized) which is then passed to fminunc in order to obtain the optimal theta.
  Also, if the gradient of costFunction can be computed, I set the 'GradObj' option to 'on' using</p>
  
  <pre><code>options = optimset('GradObj','on');
  </code></pre>
  
  <p>and code the costFunction so that it returns, as a second output argument, the gradient value g of X.
  Then I give</p>
  
  <pre><code>[theta, cost] = fminunc(@(t)(costFunction(t, X, y)), initial_theta, options);
  </code></pre>
  
  <p>where X is the data matrix and y the response. How can I implement the above in R?</p>