Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6131167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:56:34+00:00 2026-05-23T16:56:34+00:00

Is there a general way of passing a data frame with arbitrary columns (integer/factor,

  • 0

Is there a general way of passing a data frame with arbitrary columns (integer/factor, numeric, character data) from r to c and back? Pointers to close enough examples would be greatly appreciated.

Thanks.

RT

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:56:34+00:00Added an answer on May 23, 2026 at 4:56 pm

    A data.frame is a list, so along the lines of

    #include <Rdefines.h>
    
    SEXP df_fun(SEXP df)
    {
        int i, len = Rf_length(df);
        SEXP result;
        PROTECT(result = NEW_CHARACTER(len));
        for (i = 0; i < len; ++i)
            switch(TYPEOF(VECTOR_ELT(df, i))) {
            case INTSXP:
                SET_STRING_ELT(result, i, mkChar("integer"));
                break;
            case REALSXP:
                SET_STRING_ELT(result, i, mkChar("numeric"));
                break;
            default:
                SET_STRING_ELT(result, i, mkChar("other"));
                break;
            };
            UNPROTECT(1);
        return result;
    }
    

    and then after R CMD SHLIB df_fun.c

    > dyn.load("df_fun.so")
    > df=data.frame(x=1:5, y=letters[1:5], z=pi, stringsAsFactors=FALSE)
    > .Call("df_fun", df)
    [1] "integer" "other"   "numeric"
    

    Use GET_CLASS, GET_ATTR and other macros in Rdefines.h (or their equivalent functions, like getAttrib) to discover other information about the data frame. Note though that a data.frame has an API that can differ from its structure. So for instance the R function row.names can return something different from the value stored in the row.names attribute. I think most .Call functions operate on atomic vectors, keeping the manipulation of more complicated objects at the R level.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any easy/general way to clean an XML based data source prior to
Is there a general way to implement part of an application with JavaScript and
Is there a general way to check for an overflow or an underflow of
Is there a general, cross RDMS, way I can have a key auto generated
In Java (And in general) is there a way to make a class so
Is there a way in C# or .NET in general to create an attribute
Is there a way to make OpenGL transform a general vector I give it
Is there a general rule of thumb to follow when storing web application data
Is there a way to identify, from within a VM, that your code is
In java, is there a general way to enforce compile-time compilation? In a programming

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.