[Rcpp-devel] trouble creating a dataframe

Pratibha Rana pratibha.r.tomar at gmail.com
Tue Jun 5 20:33:53 CEST 2012


I tried another approach, and this one was also futile.

try{
        int size =  argTypes.getColumnCount();
        std::vector<RObject> inputVectors;
        inputVectors.reserve(3);
        StringVector nameVec(size);
        NumericVector lenVec(size) ;
        NumericVector scaleVec(size) ;

        for (size_t i = 0; i < size; ++i) {
            //get the datatype
            Type vt = argTypes.getColumnType(i);
            DataOID BDOid = vt.getTypeOid();

            //convert the Oid to string name
            std::string columnType = Oid2String(BDOid);

            //get the length for string types, precision for time and
numerics and scale for numerics
            int length = 0;
            int scale= 0;
            getTypeLength(vt, length, scale);

            nameVec[i] = columnType.c_str();
            lenVec[i] = length;
            scaleVec[i] = scale;
        }

        inputVectors.push_back(nameVec);
        inputVectors.push_back(lenVec);
        inputVectors.push_back(scaleVec);

        //create the dataframe
        Rcpp::List df;
        df.push_back(inputVectors[0],"datatype");
        df.push_back(inputVectors[1],"length");
        df.push_back(inputVectors[2],"scale");

        Rcpp::DataFrame df_final =  Rcpp::DataFrame::create(df);
        return df_final;

    }

On Tue, Jun 5, 2012 at 10:33 AM, Pratibha Rana
<pratibha.r.tomar at gmail.com>wrote:

> I can only create std::vectors. The list::create also fails.
>
>
> On Mon, Jun 4, 2012 at 6:48 PM, Steve Lianoglou <
> mailinglist.honeypot at gmail.com> wrote:
>
>> On Mon, Jun 4, 2012 at 6:02 PM, Dirk Eddelbuettel <edd at debian.org> wrote:
>> >
>> > On 4 June 2012 at 17:28, Pratibha Rana wrote:
>> [snip]
>>
>> > | The value of res was printed at line 159 in Vector__create.h . Using
>> Wrap()
>> > | makes it worse. I really need help. I have been trying to do this for
>> 2 days
>> > | now.
>>
>> > What about the working example I just to the list?
>> >
>> > What about the following adapted from the unit test file for dataframes:
>>
>> Or, if you're really in dire straits and assuming you've got the list
>> you want to convert to a data.frame built already: you can just pass
>> it back to R and convert it w/ `as.data.frame`.
>>
>> This will allow you to move on w/ getting the rest of the things you
>> need to work done and you can revisit this later when you're out of
>> the woods.
>>
>> -steve
>>
>> --
>> Steve Lianoglou
>> Graduate Student: Computational Systems Biology
>>  | Memorial Sloan-Kettering Cancer Center
>>  | Weill Medical College of Cornell University
>> Contact Info: http://cbio.mskcc.org/~lianos/contact
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20120605/0b31c486/attachment-0001.html>


More information about the Rcpp-devel mailing list