[Rd] Convert multiple C strings into an R character vector

Seth Falcon sfalcon at fhcrc.org
Fri Aug 10 19:58:31 CEST 2007


Jonathan Zhou <jonathan.zhou at utoronto.ca> writes:

> I was hoping someone could tell me how to convert multiple C character
> strings into an R character vector.  

Here's a quick untested sketch:


    char **yourStrings;
    int numStrings = /* the length of yourStrings */;
    int i;
    SEXP cvect;
    
    PROTECT(cvect = allocVector(STRSXP, numStrings));
    for (i = 0; i < numStrings; i++) {
        SET_STRING_ELT(cvect, i, mkChar(yourStrings[i]));
    }
    UNPROTECT(cvect);
    return cvect;


+ seth

-- 
Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center
BioC: http://bioconductor.org/
Blog: http://userprimary.net/user/



More information about the R-devel mailing list