TABLE OF CONTENTS


CmiscUtils/getListElement [ Functions ]

NAME

    getListElement --- get an element of a SEXP list by name

FUNCTION

Given an R list structure as a SEXP, get a named list element. This is taken almost verbatim from "Writing R extensions".

SYNOPSIS

466 SEXP getListElement(SEXP list, const char *str)

INPUTS

    list  a list in R memory
    str   the name of the desired element

OUTPUTS

    elmt  a pointer to the element of list whose name is str

SOURCE

470 {
471     SEXP elmt = R_NilValue, names = getAttrib(list, R_NamesSymbol);
472     int i;
473     for (i = 0; i < length(list); i++)
474      if(strcmp(CHAR(STRING_ELT(names, i)), str) == 0) {
475        elmt = VECTOR_ELT(list, i);
476        break;
477      }
478     return elmt;
479 }