Error : Expecting a single value: [extent=3]
0
0
Entering edit mode
@charlesgwellem-16293
Last seen 2.7 years ago
Germany

I will be grateful for any hint on how to correct the code. I am a beginner with the Rccp package and R programming. I have an R data frame df with special columns (columns with lists), to simulate my processed gene expression data:

df<- data.frame(w= 1:3, x=3:5, y=6:8, z = I(list(1:2, 1:3, 1:4)))
df <- as.data.frame(do.call(cbind, lapply(df[1:3], function(x) Map("*", df$z, x))))

>df

           w                x                  y
        1, 2             3, 6              6, 12
     2, 4, 6         4, 8, 12          7, 14, 21
3, 6, 9, 12    5, 10, 15, 20      8, 16, 24, 32

My goal is to have a data frame df1 by interfacing C++ and R in order to speed up my code, while preserving the data frame structure.

df1 <- as.data.frame (4*sin(df*pi))

I have attempted :

library(Rcpp)
cppFunction('NumericVector transfo(Rcpp::DataFrame x) {
  int nrow = x.nrow(), ncol = x.ncol();
           NumericVector out(nrow*ncol);
           int pi;
           int vol = 4;
           for (int j = 0; j < ncol; j++) {
           for (int i = 0; i < nrow; i++) {
           out[i, j] = sin(x[i,j]*pi)*vol;
           }
           }
           return out;
           }')

 

But with transfo(df): I get the error :

Expecting a single value: [extent=3]

I will be grateful for any hint on how to make the code work. 

bioconductor rcpp r • 3.3k views
ADD COMMENT
0
Entering edit mode

This is really not the correct support site for Rccp, which is a CRAN package. Try R-help or stackoverflow.

ADD REPLY

Login before adding your answer.

Traffic: 925 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6