Re: [Rcpp-devel] Idiom for accessing scalars

2012-01-07 Thread Dirk Eddelbuettel
On 7 January 2012 at 19:02, Romain François wrote: | Not thinking about a rewrite, just adding e.g. this for int: | | template <> inline int as( SEXP x, | ::Rcpp::traits::r_type_primitive_tag ) { | return Rf_asInteger( x ) ; | } | | so that we let R's asInteger do the actua

Re: [Rcpp-devel] Idiom for accessing scalars

2012-01-07 Thread Romain François
Le 07/01/12 18:55, Dirk Eddelbuettel a écrit : On 7 January 2012 at 18:40, Romain François wrote: | Le 07/01/12 18:36, Douglas Bates a écrit : |> On Sat, Jan 7, 2012 at 10:55 AM, Dirk Eddelbuettel wrote: |>> On 7 January 2012 at 10:04, Douglas Bates wrote: |>> | 2012/1/7 Romain François: |>>

Re: [Rcpp-devel] Idiom for accessing scalars

2012-01-07 Thread Dirk Eddelbuettel
On 7 January 2012 at 18:40, Romain François wrote: | Le 07/01/12 18:36, Douglas Bates a écrit : | > On Sat, Jan 7, 2012 at 10:55 AM, Dirk Eddelbuettel wrote: | >> On 7 January 2012 at 10:04, Douglas Bates wrote: | >> | 2012/1/7 Romain François: | >> |> Le 06/01/12 20:46, Douglas Bates a écrit :

Re: [Rcpp-devel] Idiom for accessing scalars

2012-01-07 Thread Romain François
Le 07/01/12 18:36, Douglas Bates a écrit : On Sat, Jan 7, 2012 at 10:55 AM, Dirk Eddelbuettel wrote: On 7 January 2012 at 10:04, Douglas Bates wrote: | 2012/1/7 Romain François: |> Le 06/01/12 20:46, Douglas Bates a écrit : |> |>> On Fri, Jan 6, 2012 at 1:12 PM, Dirk Eddelbuettel wrote: |

Re: [Rcpp-devel] Idiom for accessing scalars

2012-01-07 Thread Douglas Bates
On Sat, Jan 7, 2012 at 10:55 AM, Dirk Eddelbuettel wrote: > > On 7 January 2012 at 10:04, Douglas Bates wrote: > | 2012/1/7 Romain François : > | > Le 06/01/12 20:46, Douglas Bates a écrit : > | > > | >> On Fri, Jan 6, 2012 at 1:12 PM, Dirk Eddelbuettel   > wrote: > | >>> > | >>> On 6 January 2012

Re: [Rcpp-devel] Idiom for accessing scalars

2012-01-07 Thread Romain François
Le 07/01/12 17:04, Douglas Bates a écrit : 2012/1/7 Romain François: Le 06/01/12 20:46, Douglas Bates a écrit : On Fri, Jan 6, 2012 at 1:12 PM, Dirk Eddelbuettelwrote: On 6 January 2012 at 12:59, Douglas Bates wrote: | On Fri, Jan 6, 2012 at 12:39 PM, John Chambers wrote: |>The "Rf_

Re: [Rcpp-devel] Idiom for accessing scalars

2012-01-07 Thread Dirk Eddelbuettel
On 7 January 2012 at 10:04, Douglas Bates wrote: | 2012/1/7 Romain François : | > Le 06/01/12 20:46, Douglas Bates a écrit : | > | >> On Fri, Jan 6, 2012 at 1:12 PM, Dirk Eddelbuettel  wrote: | >>> | >>> On 6 January 2012 at 12:59, Douglas Bates wrote: | >>> | On Fri, Jan 6, 2012 at 12:39 PM, John

Re: [Rcpp-devel] Idiom for accessing scalars

2012-01-07 Thread Dirk Eddelbuettel
On 7 January 2012 at 10:04, Douglas Bates wrote: | 2012/1/7 Romain François : | > Le 06/01/12 20:46, Douglas Bates a écrit : | > | >> On Fri, Jan 6, 2012 at 1:12 PM, Dirk Eddelbuettel  wrote: | >>> | >>> On 6 January 2012 at 12:59, Douglas Bates wrote: | >>> | On Fri, Jan 6, 2012 at 12:39 PM, John

Re: [Rcpp-devel] Idiom for accessing scalars

2012-01-07 Thread Douglas Bates
2012/1/7 Romain François : > Le 06/01/12 20:46, Douglas Bates a écrit : > >> On Fri, Jan 6, 2012 at 1:12 PM, Dirk Eddelbuettel  wrote: >>> >>> On 6 January 2012 at 12:59, Douglas Bates wrote: >>> | On Fri, Jan 6, 2012 at 12:39 PM, John Chambers >>>  wrote: >>> |>  The "Rf_" part of the API in parti

Re: [Rcpp-devel] Idiom for accessing scalars

2012-01-07 Thread Romain François
Le 06/01/12 20:46, Douglas Bates a écrit : On Fri, Jan 6, 2012 at 1:12 PM, Dirk Eddelbuettel wrote: On 6 January 2012 at 12:59, Douglas Bates wrote: | On Fri, Jan 6, 2012 at 12:39 PM, John Chambers wrote: |> The "Rf_" part of the API in particular is ugly and somewhat of an add-on |> forced

Re: [Rcpp-devel] Idiom for accessing scalars

2012-01-06 Thread Dirk Eddelbuettel
On 6 January 2012 at 13:46, Douglas Bates wrote: | I didn't make myself clear. What I meant was that it is not possible | to use asInteger in Rcpp and count on the name being remapped to | Rf_asInteger. Right. I had to enforce that a long time ago because the non-prefixed variants too often clas

Re: [Rcpp-devel] Idiom for accessing scalars

2012-01-06 Thread Douglas Bates
On Fri, Jan 6, 2012 at 1:12 PM, Dirk Eddelbuettel wrote: > > On 6 January 2012 at 12:59, Douglas Bates wrote: > | On Fri, Jan 6, 2012 at 12:39 PM, John Chambers > wrote: > | > The "Rf_" part of the API in particular is ugly and somewhat of an add-on > | > forced in a few examples by the use of s

Re: [Rcpp-devel] Idiom for accessing scalars

2012-01-06 Thread Dirk Eddelbuettel
On 6 January 2012 at 12:59, Douglas Bates wrote: | On Fri, Jan 6, 2012 at 12:39 PM, John Chambers wrote: | > The "Rf_" part of the API in particular is ugly and somewhat of an add-on | > forced in a few examples by the use of some common names in the macro files. | | But, as it stands, that is a

Re: [Rcpp-devel] Idiom for accessing scalars

2012-01-06 Thread Douglas Bates
On Fri, Jan 6, 2012 at 12:39 PM, John Chambers wrote: > At the risk of derailing this thread into the quicksand of programming style > > > Except when required by the specific application, my preference would be to > stay with the Rcpp idiom.  Mixing in the older C API seems to risk more > pr

Re: [Rcpp-devel] Idiom for accessing scalars

2012-01-06 Thread Dirk Eddelbuettel
On 6 January 2012 at 10:39, John Chambers wrote: | At the risk of derailing this thread into the quicksand of programming | style Au contraire: thanks for joining in. | Except when required by the specific application, my preference would be | to stay with the Rcpp idiom. Mixing in the

Re: [Rcpp-devel] Idiom for accessing scalars

2012-01-06 Thread John Chambers
At the risk of derailing this thread into the quicksand of programming style Except when required by the specific application, my preference would be to stay with the Rcpp idiom. Mixing in the older C API seems to risk more programming error. Of course, each application is different and

Re: [Rcpp-devel] Idiom for accessing scalars

2012-01-06 Thread Dirk Eddelbuettel
On 6 January 2012 at 13:00, Steve Lianoglou wrote: | Hi, | | 2012/1/6 Douglas Bates : | [snip] | > As I mentioned in another thread, I prefer the idiom | > | > int n2 = ::Rf_asInteger(n); | > | > because asInteger is part of the R API (in Rcpp it must be called as | > Rf_asInteger - the :: is a h

Re: [Rcpp-devel] Idiom for accessing scalars

2012-01-06 Thread Steve Lianoglou
Hi, 2012/1/6 Douglas Bates : [snip] > As I mentioned in another thread, I prefer the idiom > > int n2 = ::Rf_asInteger(n); > > because asInteger is part of the R API (in Rcpp it must be called as > Rf_asInteger - the :: is a hint to the compiler that it will be found > in the global namespace).  F

Re: [Rcpp-devel] Idiom for accessing scalars

2012-01-06 Thread Douglas Bates
2012/1/4 Romain François : > Le 04/01/12 14:29, Hadley Wickham a écrit : > >> Hi all, >> >> I'm still just getting my feet wet in Rcpp, so please excuse the >> naivety of my question, but is this the appropriate idiom for treating >> an input as a C++ scalar? >> >> f<- cxxfunction(signature(x = "in

Re: [Rcpp-devel] Idiom for accessing scalars

2012-01-04 Thread Steve Lianoglou
2012/1/4 Hadley Wickham : >>> And is there a standard for what you call the C++ equivalent of the R >>> arguments?  i.e. x_ = as(x) ? >> >> I don't think there's a "standard" per se, but I actually tend to do >> it the other way, ie. put the trailing slash on the incoming SEXP >> arguments so that

Re: [Rcpp-devel] Idiom for accessing scalars

2012-01-04 Thread Hadley Wickham
>> And is there a standard for what you call the C++ equivalent of the R >> arguments?  i.e. x_ = as(x) ? > > I don't think there's a "standard" per se, but I actually tend to do > it the other way, ie. put the trailing slash on the incoming SEXP > arguments so that my c(++) code is a bit less tedi

Re: [Rcpp-devel] Idiom for accessing scalars

2012-01-04 Thread Steve Lianoglou
Hi, 2012/1/4 Hadley Wickham : >> We have "as" for this, and wrap for the other way around: >> >> f<- cxxfunction(signature(x = "integer"), plugin = "Rcpp", ' >>  int x2 = as(x) ; >> >>  return wrap(x2) ; >> ') > > Got it - thanks! > > And is there a standard for what you call the C++ equivalent of

Re: [Rcpp-devel] Idiom for accessing scalars

2012-01-04 Thread Hadley Wickham
> We have "as" for this, and wrap for the other way around: > > f<- cxxfunction(signature(x = "integer"), plugin = "Rcpp", ' >  int x2 = as(x) ; > >  return wrap(x2) ; > ') Got it - thanks! And is there a standard for what you call the C++ equivalent of the R arguments? i.e. x_ = as(x) ? Hadley

Re: [Rcpp-devel] Idiom for accessing scalars

2012-01-04 Thread Romain François
Le 04/01/12 14:29, Hadley Wickham a écrit : Hi all, I'm still just getting my feet wet in Rcpp, so please excuse the naivety of my question, but is this the appropriate idiom for treating an input as a C++ scalar? f<- cxxfunction(signature(x = "integer"), plugin = "Rcpp", ' Rcpp::IntegerVect

[Rcpp-devel] Idiom for accessing scalars

2012-01-04 Thread Hadley Wickham
Hi all, I'm still just getting my feet wet in Rcpp, so please excuse the naivety of my question, but is this the appropriate idiom for treating an input as a C++ scalar? f <- cxxfunction(signature(x = "integer"), plugin = "Rcpp", ' Rcpp::IntegerVector x1(x); int x2 = x1[0]; return(Rcpp::Nu