Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display the code of a .C routine used by R function?

Tags:

r

I was studying some functions of the package rimage. If you want to see, for example, the code for the sobel.h function, you obtain:

> library(rimage)
> sobel.h
function (img) 
{
    w <- dim(img)[2]
    h <- dim(img)[1]
    imagematrix(abs(matrix(.C("sobel_h", as.double(img), as.integer(w), 
        as.integer(h), eimg = double(w * h), PACKAGE = "rimage")$eimg, 
        nrow = h, ncol = w)), noclipping = TRUE)
}

So the sobel.h function uses the C routine called sobel_h, (which is (I think) stored in the file rimage.dll).

Is there any way to see the C code of the sobel_h function?

(I speak about the package rimage for a practical example; but the answer would of course generalised to all packages that uses .C routines).

like image 277
Tommaso Avatar asked Nov 13 '10 19:11

Tommaso


2 Answers

Check this: Uwe Ligges. R Help Desk: Accessing the sources. R News, 6(4):43-45, October 2006.

In order to access the sources of compiled code (i.e., C, C++, or Fortran), it is not sufficient to have the binary version of R or a contributed package installed. Rather, it is necessary to download the sources for R or for the package.

like image 66
rcs Avatar answered Oct 16 '22 15:10

rcs


The Linux source for rimage is here: http://cran.r-project.org/src/contrib/rimage_0.5-8.1.tar.gz Windows source is here: http://cran.r-project.org/bin/windows/contrib/r-release/rimage_0.5-8.1.zip

sobel.c is in the rimage/src/ directory in the unpacked files.

like image 21
IRTFM Avatar answered Oct 16 '22 15:10

IRTFM