About me | pbdR Tech | HPSC | Phyloclustering | R_note |

R_note -- The Exploration of Statistical Software R (統計軟體 R 深度歷險)
About R_note
MS Windows

Batch jobs

Remark Lines
S4 Methods
Batch more

Good Coding
Fast Loop

PHP Call R
Basic C
R Call Fortran/C
R Call GSL
C Call R API
C Call R Objects

Make Packages
C Pointer

Section: C Pointer

  • Prolog

    Dr. Ranjan Maitra and Dr. Volodymyr Melnykov developed a lot of C functions handling high dimensional data set, using EM Algorithm to find the classifications by Model-Based Clustering, and other related interesting studies requiring high performance computing. They also accomplish their achievements with R packages. Pointer arrays are heavily used in the researchs, but skipped cleverly by some macros in C ... Dr. Maitra is a professor in Department of Statisitcs, Iowa State University, Ames, Iowa, USA, and his student, Dr. Melnykov, is a professor in Department of Statisitcs, North Dakota State University, Fargo, North Dakota, USA.

  • Story

    This is an example for demonstrate C pointer arrays by an R package, and all the functions can be wrappers for other C functions. There are three main C functions to receive data (pointer) from R, and assign data into an array, a double pointer array, and a 3D pointer array by different ways including: directly making a copy, and assigning pointer arrays to the addresses of R's objects. R and C use different arrange methods to assign "array", so it should be manipulated carefully when they are communicating with each other. These techniques are useful when we are analyzing high dimensional data set.

  • Basic Ideas
    • R use "first index goes first".
    • C use "last index goes first".
    • For 2D, make a transpose for data in R and pass to C with reversed order of dimension.
    • For 3D, make a permuation for data in R and pass to C with reversed order of dimension.

  • Code
    You can download the package
    Linux: "CPointer.tar.gz"
    Windows: "CPointer.zip"

    3 main C functions are provided test_1d(), test_2d(), and test_3d() in src/.
    2 tool C functions in "src/R_tools.c" for allocating pointer arrays.
    3 R functions test.1d(), test.2d(), and test.3d() in "R/".
    .C() is used in R, but the issues are all the same for .Call() or .External().

[ Go to top ]

Maintained: Wei-Chen Chen
E-Mail: wccsnow @ gmail.com
Last Revised: Dec 12 2016, 09:44 (CST Taipei, Taiwan)
Created: Oct 06 2003
free counters Best Resolution
small font