Yes.  I'll take a look, and I should have a fix out a a few days.

The externalptr change is correct since this is how swig represents unknown objects, but matrix is a special object in swig which needs to be recognized.

Can you give me a small test case that generates a matrix that fails?

On Tue, Feb 25, 2014 at 3:28 AM, William S Fulton <> wrote:
On 24/02/14 15:48, Soeren Sonnenburg wrote:
Dear all,

trying to get swig-R to work with shogun on debian sid (swig 2.0.11)
I am seeing a regression from swig2.0.4 with output typemaps no longer
working. Due to 2 newly added lines

   if (inherits(self, "ExternalReference")) self = slot(self,"ref")
   if (inherits(preallocated, "ExternalReference")) preallocated =

Searching CHANGES in swig src points to

2012-08-26: drjoe
             [R] make ExternalReference slot ref to contain reference

The issue manifests like this:

Welcome! This is SHOGUN version 3.2.1

fm_train_real <- t(as.matrix(read.table('../data/fm_train_real.dat')))
fm_test_real <- t(as.matrix(read.table('../data/fm_test_real.dat')))

# gaussian
[1] "Gaussian"

feats_train <- RealFeatures()
dump <- feats_train$set_feature_matrix(fm_train_real)
feats_test <- RealFeatures()
dump <- feats_test$set_feature_matrix(fm_test_real)
width <- 1.9

kernel <- GaussianKernel(feats_train, feats_train, width)
km_train <- feats_train$get_feature_matrix()
Error in validObject(.Object) :
   invalid class "_p_shogun__SGMatrixT_double_t" object: invalid object
for slot "ref" in class "_p_shogun__SGMatrixT_double_t": got class
"matrix", should be or extend class "externalptr"
Calls: <Anonymous> ... f -> new -> initialize -> initialize -> validObject

I guess it is easy to figure out how to fix it.

Joe, could you look at this change you made please?