[Rcpp-devel] Rcpp:integer class?

romain at r-enthusiasts.com romain at r-enthusiasts.com
Tue Dec 21 18:33:01 CET 2010


Hello, 

You can use 

int index = as<int>( v1 ) ;

also, you don't need to write the loop yourself and you can directly either call xD.row(index) or xD(index,_). 

For example: 

require(inline)
require(Rcpp)

src2 <- '
  int index = as<int>(v1);  
  IntegerMatrix xD(D);
  IntegerVector Drow = xD.row(index) ; 
  return Drow;
'
D <- matrix( as.numeric(1:16), nr= 4 )
rowExtraction <- cxxfunction(
    signature(D="matrix",v1="integer"),body=src2,
    plugin="Rcpp",verbose=TRUE)
rowExtraction(D,1)


Romain


 Le mar 21/12/10 17:23, "Cedric Ginestet" c.ginestet05 at googlemail.com a écrit:
> Dear Rcpp experts, 
> 
> I am trying to find a way a single integer to a function. See the
> code below. I am here obliged to translage v1 as an IntegerVector and
> then to select only its first argument. Is there a better way of doing
> this, where I don't have to declare an entire vector for such a task?
> 
> ###########################################
> src2  INTEGERVECTOR X1(V1); 
> IntegerMatrix xD(D);
> IntegerVector Drow(xD.ncol()); 
> for(int i=0; i return Drow;
> '
> rowExtraction  cxxfunction(signature(D="matrix",v1="integer"),body=src2,plugin="Rcpp",verb
> ose=TRUE)rowExtraction(D,1)
> ############################################
> 
> Thank you very much, 
> Cedric 
> 
> -- 
> Cedric Ginestet 
> Centre for Neuroimaging Sciences (L3.04) 
> NIHR Biomedical Research Centre 
> Department of Neuroimaging 
> Institute of Psychiatry, Box P089 
> King's College London 
> De Crespigny Park
> London 
> SE5 8AF 
> Tel: (+44) 20-3228-3052
> Fax: (+44) 20-3228-2116
> Email: cedric.ginestet at kcl.ac.uk
> 
> 
> 



More information about the Rcpp-devel mailing list