简体   繁体   中英

What does the “install” function mean in C syntax?

I'm trying to understand the C code called by the R package ucminf. The following code is from the file interface.c found at https://cran.r-project.org/src/contrib/ucminf_1.1-4.tar.gz :

#include <R.h>
#include <Rinternals.h>  //R internal structures
#include <R_ext/RS.h>    //F77_CALL etc.

// Declare FORTRAN routine for use in C
extern void F77_NAME(ucminf)(int*, double[], double*, double[],
                 int*,double[],int*,int*,int*,double[],SEXP);

/*-------------------------------------------------------------------------------
  Define C functions that calls user defined function in R
*/

void installPar(int nn, double x[], SEXP rho) {
    int i;
    SEXP PAR = findVarInFrame(rho, install(".x"));
    double *xpt = REAL(PAR);
    if (LENGTH(PAR) != nn)
    error("Dimension mismatch, length(.x) = %d != n = $d", LENGTH(PAR), nn);
    for (i = 0; i < nn; i++) xpt[i] = x[i] ;
}

rho is an environment created in R, and it contains the vector .x . My best guess is that the line SEXP PAR = findVarInFrame(rho, install(".x")); is setting PAR equal to .x , but what does the install() command do?

This is such a simple question that I was surprised I couldn't find the answer online - searching for "install c syntax" turned up lots of information about how to install compilers, but I couldn't find anything about the command. Any suggestions for keywords to make my searches more effective would be appreciated.

This code is part of an R extension I think, and therefore the use of install here is a function call to the RC API for Writing Extension . What this does is create the symbol .x in the current symbol table (or return a reference to the existing .x symbol). The linked document does indicate that using install is harmless if the symbol already exists, and is a good way of looking up the symbol if that's what you actually want to do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM