On 17 March 2012 at 14:34, Dan Kelley wrote: | I am having trouble handing "raw" data to a C function, using "cfunction", as demonstrated in the function and output pasted below. Can anyone suggest what I'm doing incorrectly? Thanks. Dan Kelley [Dalhousie University].
Don't use the .C convention: R> library(inline) R> R> code <- 'Rprintf("inside f(), b is 0X%x\\n", *b);' R> f <- cfunction(sig=signature(b="raw"), + body=code, + convention=".C") R> b <- as.raw(0x0f) R> for (i in 1:5) + f(b) inside f(), b is 0X90 inside f(), b is 0X80 inside f(), b is 0X70 inside f(), b is 0X60 inside f(), b is 0X30 R> R> f2 <- cfunction(sig=signature(b="raw"), body=' + Rprintf("inside f(), b is 0X%x\\n", AS_RAW(b)); + return(R_NilValue); + ') R> b <- as.raw(0x0f) R> for (i in 1:5) + f2(b) inside f(), b is 0X39bf9e8 inside f(), b is 0X39bf9e8 inside f(), b is 0X39bf9e8 inside f(), b is 0X39bf9e8 inside f(), b is 0X39bf9e8 R> R> Dirk -- "Outside of a dog, a book is a man's best friend. Inside of a dog, it is too dark to read." -- Groucho Marx ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.