Interfacing pre-existing C++ library from R
On Mon, 25 Feb 2002, Alexander Duering wrote:
Hello,
I'm trying to link a large in-house C++ library into R. So far, I've managed to to most of what I want, but I have one remaining question and a suggestion.
The suggestion first: I've found it useful to put
#ifdef __cplusplus
extern "C" {
#endif
and
#ifdef __cplusplus
}
#endif
around the function prototypes in Rinternals.h (in /usr/local/lib/R/include
on my Red Hat 7.2 box) so my dynamic linker would no longer complain about mangling-related undefined symbols. Also, I had to use #define USE_RINTERNALS before including them in order to get a few macros I suppose are natural to use. To be honest, I do think the include files could do with a bit of cleaning up, in particular in view of linking in C++ code, but no complaints (I'm very happy to have R as it is). Well, prior to R 1.4.1 Rinternals.h would not work with many C++ compilers, and some changes were made because a package writer had assumed it would (as it did with his version of g++, although not with mine nor with Solaris' C++). Those blocks would indicate that we believed that Rinternals.h was safe to use in C++ code, and at the last minor release (1.4.0) it wasn't. It's under consideration for 1.5.0 if we can be sure that it is now fully C++ compliant. The `Writing R Extensions' manual is careful not to include Rinternals.h in the description of what headers can be used with C++. One issue is that these headers get changed frequently, and we need to be able to verify such claims automatically. There is nothing to stop you making your own header which includes Rinternals.h between those blocks of code, of course.
My question is this: Our library makes extensive use of matrices of mixed
type, i.e., I would need to pass in and out objects that are logically of rectangular structure, but some cells contain numbers, others strings. I had initially hoped to be able to use data frames for that, but I realise that columns have to be of identical mode. I could, if nothing else works, use string matrices, but that would be very very unsatisfactory (and take ages, because I'd have to check, and possibly convert, each matrix element). Could somebody please suggest the 'natural' R data structure for this kind of object? I'm using cell arrays in Matlab and lists of lists in Perl for that purpose, if it's any help. A matrix list? R lists are just vectors with elements of different types, and R matrices are just vectors with a dimension attribute.
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._