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 9038427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:29:14+00:00 2026-06-16T09:29:14+00:00

I would like to implement some R package, written in C code. The C

  • 0

I would like to implement some R package, written in C code.

The C code must:

  • take an array (of any type) as input.
  • produce array as output (of unpredictable size).

What is the best practice of implementing array passing?

At the moment C code is called with .C(). It accesses array directly from R, through pointer. Unfortunately same can’t be done for output, as output dimensions need to be known in advance which is not true in my case.

Would it make sense to pass array from C to R through a file? For example, in ramfs, if using linux?

Update 1:
Here the exact same problem was discussed.
There, possible option of returning array with unknown dimensions was mentioned:

Splitting external function into two, at the point before calculating the array but after dimensions are known. First part would return dimensions, then empty array would be prepared, then second part would run and populate the array in R.

In my case full dimensions are known only once whole code is executed, so this method would mean running C code twice. Taking a guess on maximal array size isn’t optional either.

Update 2: It seems only way to do this is to use .Call() instead, as power suggested. Here are few good examples: http://www.sfu.ca/~sblay/R-C-interface.ppt.

Thanks.

  • 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-06-16T09:29:15+00:00Added an answer on June 16, 2026 at 9:29 am

    What is the best practice of implementing array passing?

    Is the package already written in ANSI C? .C() would then be quick and easy.

    If you are writing from scratch, I suggest .Call() and Rcpp. In this way, you can pass R objects to your C/C++ code.

    Would it make sense to pass array through a file?

    No

    Read “Writing R Extensions”.

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

Sidebar

Related Questions

I would like to implement some Drag-select functionality into a project of mine but
I would like to implement some live elements to an existing PHP app. So
I would like to implement a distinct thread for each route in apache camel.I
I would like to implement a very simple way to store a variable containing
I would like to implement a function with R that removes repeated characters in
I would like to implement a simple queueing service specific to a project. Where
I would like to implement a switch button, android.widget.Switch (available from API v.14). <Switch
I would like to implement a simple AR desktop application. This application should first
I would like to implement something similar to 37Signals's Yellow Fade effect. I am
We would like to implement a web form that automatically saves content at regular

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.