Skip to content
Prev 36159 / 63421 Next

for help on building a R package with several R function and a bunch of c, c++

Alex,
On Mar 8, 2010, at 12:16 , alex46015 at yahoo.com wrote:

            
Yes, that's perfect - for the kind of usage you don't need Rcpp at all  
- R supports C++ sources out of the box. Just make sure your tranptest  
function is either in a .c file or you put
extern "C"
in front of it if it's in .cpp , e.g:

foo.cpp:
extern "C" void tranptest(char **fn, double *par) {
...
}
yes, in R/foo.R (replace "foo" by any name you want)
If you have a namespace just add
useDynLib(foo)
where "foo" is the name of your package. If you don't have a namespace  
(or don't kwno what that is ;)) just add a file R/zzz.R with the  
following content to your package:
.First.lib <- function(libname, pkgname) library.dynam("foo", pkgname,  
libname)
where "foo" is the name of your package.
It's really simple - you don't need to install the package to test it.  
Assuming "foo" is the name of your package:
Build the sources:
R CMD SHLIB -o foo.so *.c*

start R in the same directory:
R
# load the library you just compiled
dyn.load("foo.so")
# test your code
.C("tranptest", c("file1", "file2"), as.double(1,2,3,4))

Cheers,
Simon

Thread (14 messages)

alex46015 at yahoo.com for help on building a R package with several R function and a bunch of c, c++ Mar 5 Dirk Eddelbuettel for help on building a R package with several R function and a bunch of c, c++ Mar 5 alex46015 at yahoo.com for help on building a R package with several R function and a bunch of c, c++ Mar 5 Romain Francois for help on building a R package with several R function and a bunch of c, c++ Mar 7 alex46015 at yahoo.com for help on building a R package with several R function and a bunch of c, c++ Mar 7 Romain Francois for help on building a R package with several R function and a bunch of c, c++ Mar 7 alex46015 at yahoo.com for help on building a R package with several R function and a bunch of c, c++ Mar 8 Romain Francois for help on building a R package with several R function and a bunch of c, c++ Mar 8 Dirk Eddelbuettel for help on building a R package with several R function and a bunch of c, c++ Mar 8 Simon Urbanek for help on building a R package with several R function and a bunch of c, c++ Mar 8 Simon Urbanek for help on building a R package with several R function and a bunch of c, c++ Mar 8 alex46015 at yahoo.com for help on building a R package with several R function and a bunch of c, c++ Mar 8 Simon Urbanek for help on building a R package with several R function and a bunch of c, c++ Mar 8 alex46015 at yahoo.com for help on building a R package with several R function and a bunch of c, c++ Mar 8