Thread: C code and R question

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    2

    C code and R question

    Hello C-programmers,

    I have been using R for a while and am stuck because I don`t understand some C code that R is calling. Here is the problem:

    In R, the following matrix (delay function) is created:

    Code:
    fractions <- c(0,0.09,0.41,1)
    distance <- c(0,51,360,920)
    delay <- cbind(fractions, distance)
    the result in R looks like this:

    fractions distance
    [1,] 0.00 0
    [2,] 0.09 51
    [3,] 0.41 360
    [4,] 1.00 920

    This is fine. Now the delay matrix is sent to a c script using the command:

    Code:
    Result <- .C(“samplescript”, 
    PACKAGE =”samplepackage”,
    as.double(as.matrix(delay))
    as.integer(length(delay[,1])))

    then in the c “samplescript”, the following lines are executed:

    Code:
    void param_init(double *delay, int nch)
    
    /* reading delay function */
    
    	for(i=0; i<nch; i++){
    		params.d[i] = delay[i];
    		params.Ad_r[i] = delay[i+nch];
    	}
    What are the values of Ad_r [i]? Is params.d [i] a vector or a matrix? I don`t understand what the C code does with the delay function.

    Thank you for your help!

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    The C code appears to merely by copying the passed data into an internal structure.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    2
    Thank you for your reply, Dino.

    So Ad_r[i] is the second column of the delay function and d[i] is the first column (distance) of the delay function?

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,794
    Quote Originally Posted by chnebu View Post
    Thank you for your reply, Dino.

    So Ad_r[i] is the second column of the delay function and d[i] is the first column (distance) of the delay function?
    There is no delay function in this code
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed