From sfalcon at fhcrc.org  Fri Aug 10 19:58:31 2007
From: sfalcon at fhcrc.org (Seth Falcon)
Date: Fri, 10 Aug 2007 10:58:31 -0700
Subject: [Rd] Convert multiple C strings into an R character vector
In-Reply-To: <12095059.post@talk.nabble.com> (Jonathan Zhou's message of "Fri\,
	10 Aug 2007 10\:35\:52 -0700 \(PDT\)")
References: <12095059.post@talk.nabble.com>
Message-ID: <m2fy2rclvc.fsf@fhcrc.org>

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/



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