[R] R API - optim
Dirk Eddelbuettel
edd at debian.org
Sun Oct 14 06:20:06 CEST 2007
On 14 October 2007 at 05:58, Wang Chengbin wrote:
| I am trying to use the R API to call optim functions (nmmin, vmmin, lbfgsb,
| etc.) through a C program but I couldn't find the shared library to link
| under the R-2.6.0 build which is compiled under Linux (REL5).
You can't just call an _R_ function from a _C_ program as you do below.
| extern int Rf_initEmbeddedR(int argc, char *argv[]);
| int main()
| {
| char *argv[]= {"nmminDemo", "--gui=none", "--silent"}; const int argc =
| 3;
|
| double initial[1] = {1.5};
| double result[1];
| double value;
| int convergenceCode;
|
| /*
| * The following values are based on the help
| * page for optim.
| */
|
|
| const double abstol = 1e-16;
| const double reltol = 1e-8;
| const double alpha = 1.0; /* reflection factor */ const double beta =
| 0.5; /* contraction factor */ const double gamm = 2.0; /* expansion factor
| */ const int trace = 0; /* tracing on */
| int fncount;
| const int maxit = 10000;
| Rf_initEmbeddedR(argc, argv);
|
| nmmin(1, initial, result, &value, parabola,
Not a function at the C level.
You need to rethink what you want to do, and how you go about it. Go back to
the R Extensions manual, or look for example at Rserve by Simon which allows
you to 'think in terms of R functions' but access them via a network layer
(which can be, which doesn't have to be, on the same machine).
Hope this helps, Dirk
--
Three out of two people have difficulties with fractions.
More information about the R-help
mailing list