Perfect, I'll fix the code to not generate that line if the pointer
outputs swig
1) I'm not sure but I think it is.
2) You should email to swigdevel but make sure that I'm included in
the email.
There may be some people on swigdevel that are also rswig users but I'm still
the main support contact,
I'm the main author of RSWIG and hence of RSWIGQuantlib
On Thu, Jul 11, 2013 at 2:56 AM, Paolo Tenconi <paolo.tenconi@...> wrote:
> Hi Joseph,
> yes commenting out ans < new("_p_SEXP", ref=ans) it works well. One
> question about: if I type
> a<convolveCpp(x,y)
> then "a" is taken under the responsibility of the garbage collector or not?
> I'd like to become a good user of RSwig, swigdevel is the right place
> where I can send/answer questions and find examples to avoid to bother you
> directly?
>
> If you allow me, you're the ideator/mantainer of the swig to R interface?
> And regarding RSwigQuantLib you're the originator/mantainer of the
> project?
> I work on structured products (quantarea) in Switzerland (forced to use
> Excel/Matlab at work) and in my spare time I'd like to get back to C++/R
> (the languagues I workd with in the past and I like best).
>
> Bye, Paolo
>
>
>
>
>
>
>
>
> 2013/7/10 Joseph Wang <joequant@...>
>>
>> Can you try this and let me know if this works?
>>
>> Manually remove the
>>
>> ans < new("_p_SEXP", ref=ans);
>>
>> From the RSWIG wrapper file. If that works, then I'll modify the R
>> code generator remove
>> that line if its returning an _p_SEXP.
>>
>>
>>
>> On Tue, Jul 9, 2013 at 6:05 PM, Joseph Wang <joequant@...> wrote:
>> > Thanks. I'll take a look tomorrow. This looks to be one of those
>> > things that's
>> > either a quick fix, or totally impossible, and I'll be able to let you
>> > know which
>> > tomorrow.
>> >
>> > On Mon, Jul 8, 2013 at 6:59 AM, Paolo Tenconi <paolo.tenconi@...>
>> > wrote:
>> >> Hi Joseph,
>> >> I've a question about R/Swig, I hope you could give me an insight.
>> >> I want to return a SEXP structure
>> >>
>> >> ================ CPP ======================
>> >> SEXP convolveCpp(SEXP x, SEXP y) {
>> >> NumericVector a(x), b(y);
>> >> int na = a.size(), nb = b.size();
>> >> int nab = na + nb  1;
>> >> NumericVector xab(nab);
>> >> for (int i = 0; i < na; i++)
>> >> for (int j = 0; j < nb; j++)
>> >> xab[i + j] += a[i] * b[j];
>> >> return xab; //Rcpp NumericVector is automatically casted to SEXP
>> >>
>> >> }
>> >>
>> >>
>> >> ================ SWIG INTERFACE FILE ======================
>> >> extern "C" SEXP convolveCpp(SEXP x, SEXP y);
>> >>
>> >>
>> >> However Swig tries to return a pointer to SEXP, which doesn't work in R
>> >> (please see below "test in R")
>> >>
>> >>
>> >> ================ CPPWRAP ======================
>> >> SWIGEXPORT SEXP
>> >> R_swig_convolveCpp ( SEXP x, SEXP y, SEXP s_swig_copy)
>> >> {
>> >> SEXP result;
>> >> SEXP arg1 ;
>> >> SEXP arg2 ;
>> >> unsigned int r_nprotect = 0;
>> >> SEXP r_ans = R_NilValue ;
>> >> VMAXTYPE r_vmax = vmaxget() ;
>> >>
>> >> arg1 = x;
>> >> arg2 = y;
>> >> result = convolveCpp(arg1,arg2);
>> >> r_ans = result;
>> >> vmaxset(r_vmax);
>> >> if(r_nprotect) Rf_unprotect(r_nprotect);
>> >>
>> >> return r_ans;
>> >> }
>> >>
>> >> ================ RWRAP ======================
>> >> `convolveCpp` = function(x, y, .copy = FALSE)
>> >> {
>> >> if(inherits(x, "ExternalReference")) x = slot(x,"ref")
>> >> if(inherits(y, "ExternalReference")) y = slot(y,"ref")
>> >> ;ans = .Call('R_swig_convolveCpp', x, y, as.logical(.copy),
>> >> PACKAGE='QLswig');
>> >> ans < new("_p_SEXP", ref=ans);
>> >>
>> >> ans
>> >>
>> >> }
>> >>
>> >> ================ TEST IN R ======================
>> >> convolveCpp(x,y)
>> >> Errore in getClass(Class, where = topenv(parent.frame())) :
>> >> “_p_SEXP” is not a defined class
>> >>
>> >> # This works (the structure is passed directly back to R as is)
>> >> .Call('R_swig_convolveCpp', x, y, FALSE)
>> >>
>> >>
>> >>
>> >> Is there a way to return directly SEXP to R without the pointer?
>> >>
>> >> Many thanks for any help
>> >> Paolo
>> >>
>> >>
>> >>
>
>
