beandip beandip - 1 month ago 4x
R Question

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

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] ;

is an environment created in R, and it contains the vector
. My best guess is that the line
SEXP PAR = findVarInFrame(rho, install(".x"));
is setting
equal to
, but what does the
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 thing, and therefore the use of install here is a function call to the R C 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.