Assigning a numeric value within an R List directly to a NumericVector in C++

I would like to place the double (precision floating point) values returned from the fisher.test function into 2 vectors, from within R C++.

When assigning to a double as below, things work as expected for the p value, and the lower bound of the confidence interval, but not for the upper bound of the confidence interval:

// perform Fisher Exact test
IntegerVector v = { 1, 2, 3, 4 };
v.attr("dim") = Dimension(2, 2);
Function f("fisher.test");
List fe = f(v);
// now assign to variables
List sublist = fe["p.value"];
double pValue = sublist[0];
Rcout << "pValue:" << pValue;
sublist = fe["conf.int"];
NumericVector cis = sublist[0];
double ci_upperBound = cis[1];
Rcout << "ub:" << ci_upperBound ;

Assigning to the NumericVectors as below, and the upper bound of the confidence interval above doesn't work (values are assigned, but not the correct values, as if the pointer is misaligned).

NumericVector pValues(1);
NumericVector ciLowerBounds(1);
// (then perform Fisher test as per above)
// now assign to variables
List sublist = fe["p.value"];
pValues[0] = sublist[0];
Rcout << "pValue:" << pValues[0];
sublist = fe["conf.int"];
NumericVector cis = sublist[0];
ciUpperBounds[0] = cis[1];

I have tried using pValues[0] = Rcpp::as<double>sublist[0]; but RStudio tells me this is assigning from an incompatible type.

Can you please help me assign the p.value and upper bound of the confidence interval directly to the respective NumericVectors at the appropriate indicies. thank you.

OK got it - the function returns a NumericVector, not a list. All working well now - thank you.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.