From edd at debian.org  Tue May 14 16:17:35 2013
From: edd at debian.org (Dirk Eddelbuettel)
Date: Tue, 14 May 2013 09:17:35 -0500
Subject: [Rd] =?utf-8?q?invalid_operands_of_types_=E2=80=98SEXPREC*?=
	=?utf-8?b?4oCZIGFuIGQg4oCYUl9sZW5fdOKAmSB0byBiaW5hcnkg4oCYb3BlcmF0?=
	=?utf-8?b?b3Iv4oCZIHdpdCBoIFJjcHAu?=
In-Reply-To: <CAGBzz=L=-BMjx0fZP76G4GEZUpXAs40_HMK+Q6EPZMSW=KsO-A@mail.gmail.com>
References: <CAGBzz=Jg5KSKE=0g_i8EyhfjR_k_6ivPpyAmFHhKyVHuQbOLVQ@mail.gmail.com>
	<20882.16014.789871.565579@max.nulle.part>
	<CAGBzz=L=-BMjx0fZP76G4GEZUpXAs40_HMK+Q6EPZMSW=KsO-A@mail.gmail.com>
Message-ID: <20882.18303.905778.385712@max.nulle.part>


On 14 May 2013 at 06:47, Xiao He wrote:
| Thank you!
| 
| I will send my reply to Rcpp-devel from now on Re: my question -. Since I
| thought cppFunction() allows vectorized operations, I thought any R functions I
| call from R would also allow it. pbeta() within R can be specified as ?pbeta
| (runif(10), 1, 2) where the first argument is a vector. 


And of course so does the pbeta() we offer in Rcpp, and so does the example I
posted below.

| the function sequence()
| basically takes an integer, and produce a vector of consecutive integers
| starting from 1 to the provided value.?

Ie the same as typing  1:N  ?

Dirk
 
| 
| Best,
| Xiao
| 
| On Tue, May 14, 2013 at 6:39 AM, Dirk Eddelbuettel <edd at debian.org> wrote:
| 
| 
|     On 13 May 2013 at 21:42, Xiao He wrote:
|     | Dear R-Developers,
|     |
|     | I just started learning how to use Rcpp. Earlier while using it, I
|     | encountered an error as shown below:
|     |
|     | file74d8254b96d4.cpp: In function ?Rcpp::NumericVector
|     | foo(Rcpp::NumericVector, Rcpp::NumericVector, Rcpp::NumericVector,
|     | Rcpp::Function, Rcpp::Function)?:
|     | file74d8254b96d4.cpp:10: error: invalid operands of types ?SEXPREC*?
|     and
|     | ?R_len_t? to binary ?operator/?
|     | make: *** [file74d8254b96d4.o] Error 1
|     |
|     | Below is a mock function that can reproduce this error. I wonder if
|     anyone
|     | can tell me what is the problem here. Thank you in advance!!
|     |
|     | foo<-cppFunction('
|     | ? ?NumericVector foo(NumericVector q, NumericVector shape1,
|     NumericVector
|     | shape2, Function pbeta, Function sequence){
|     | ? ? ? ? ?NumericVector output(q.size());
|     | ? ? ? ? ?output=pbeta(sequence(q.size())/q.size(), shape1, shape2);
|     | ? ? ? ? return output;
|     | ?}
|     | ?')
| 
|     Really briefly:
| 
|     ?1) ?Wrong mailing list. Rcpp question are to be sent to rcpp-devel
| 
|     ?2) ?Possible error in your function setup. ?Why do you supply pbeta?
|     ?What is sequence?
| 
|     ?3) ?Error in how you call pbeta. ?The first argument is a vector, the
|     other
|     ? ? ?two are scalars.
| 
|     ?4) ?Compiler error is pretty clear for once: it does not understand the
|     ? ? ?division, and you only have one so look there.
| 
| 
|     Here is a minimal working example:
| 
|     library(Rcpp)
|     foo<-cppFunction('NumericVector foo(NumericVector q, double shape1, double
|     shape2){
|     ? return pbeta(q, shape1, shape2); ? ? ? ? ? ? ? ? ? ? ? ? ?
|     ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
|     ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
|     ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?}
|     ')
| 
|     for which I get
| 
|     R> source('/tmp/foo.R')
|     R> foo(seq(0.1, 0.5, by=0.1), 2, 3)
|     [1] 0.0523 0.1808 0.3483 0.5248 0.6875
|    
|     Dirk
| 
|     --
|     Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
| 
| 

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com



[Rd] =?utf-8?q?invalid_operands_of_types_=E2=80=98SEXPREC*?= =?utf-8?b?4oCZIGFuIGQg4oCYUl9sZW5fdOKAmSB0byBiaW5hcnkg4oCYb3BlcmF0?= =?utf-8?b?b3Iv4oCZIHdpdCBoIFJjcHAu?=
Dirk Eddelbuettel