[Rcpp-devel] What is the best practice to expose a C st ructure from 3rd party library into R?

Dirk Eddelbuettel edd at debian.org
Tue Jul 30 13:37:06 CEST 2013


On 30 July 2013 at 11:26, Wush Wu wrote:
| Thanks for your suggestion, Dirk.

Glad to have been of assistance.  What you were trying to do (hold on to and
shield a connection object), Modules are a very fine tool.
 
| I'll try to rewrite Rhiredis based on your approach and provide a similar
| rredis interface. If everything is good, I'll try to make it on CRAN if it is
| possible.

I'd be happy to help. 

The one thing it needs is a C-level access to serialization which would help
with the overall speed gain.  Right now we're not all that much faster than
the rredis package.  Below is a simple benchmark (which is part of my git
repo 'rhiredis') that attempts to be honest in the comparison to rredis.

Dirk


library(rhiredis)
library(rredis)
library(rbenchmark)

data(trees)
fit <- lm(log(Volume) ~ log(Girth) + log(Height), data=trees)

rawfit <- rawToChar(serialize(fit,NULL,ascii=TRUE))

redis <- new(Redis)
rredis::redisConnect()

hiredis <- function() redis$exec(paste("SET fits1 ",
                                       rawToChar(serialize(fit,NULL,ascii=TRUE)),
                                       sep=""))
rredis <- function() rredis::redisSet("fits2", fit)

res <- benchmark(hiredis(), rredis(), replications=100)[,1:4]
print(res)

all.equal(unserialize(charToRaw(redis$exec("GET fits1"))), fit)
all.equal(rredis::redisGet("fits2"), fit)





-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com


More information about the Rcpp-devel mailing list