Skip to content

[Rcpp-devel] IntegerVector initialization

5 messages · Gregor Gorjanc, Dirk Eddelbuettel, Romain Francois

#
This is a minor thing but caused some confusion to me:

IntegerVector foo1(2, 4.0);  // works
IntegerVector foo2(2, 4);    // throws error

while

IntegerVector bar1 = IntegerVector::create(4.0, 4.0);  // works
IntegerVector bar2 = IntegerVector::create(4, 4);      // works

Bug or feature?

Best,
/g
#
On 12 January 2012 at 11:29, Gregor Kastner wrote:
| This is a minor thing but caused some confusion to me:
| 
| IntegerVector foo1(2, 4.0);  // works
| IntegerVector foo2(2, 4);    // throws error

What were you expecting with the second argument?  A 'fill' value?  Arguably,
int should then work.
 
| while
| 
| IntegerVector bar1 = IntegerVector::create(4.0, 4.0);  // works
| IntegerVector bar2 = IntegerVector::create(4, 4);      // works

::create is very different from the constructors above.
 
| Bug or feature?

Depends. What were you trying to do?

Dirk
#
Yes, inspired by

// ... with a default for all values
NumericVector xx(10, 2.0);

on page 1 of Rcpp-quickref's "Create simple vectors" box.
Sure, but in this case I get the same results: "c(4L,4L)", right?

Best,
/g
#
On 13 January 2012 at 00:28, Gregor Kastner wrote:
| > | This is a minor thing but caused some confusion to me:
| > | 
| > | IntegerVector foo1(2, 4.0);  // works
| > | IntegerVector foo2(2, 4);    // throws error
| > 
| > What were you expecting with the second argument?  A 'fill' value?
| > Arguably, int should then work.
| 
| Yes, inspired by
| 
| // ... with a default for all values
| NumericVector xx(10, 2.0);
| 
| on page 1 of Rcpp-quickref's "Create simple vectors" box.

Very reasonable assumption :)   That seems to be a buglet.

| > | while
| > | 
| > | IntegerVector bar1 = IntegerVector::create(4.0, 4.0);  // works
| > | IntegerVector bar2 = IntegerVector::create(4, 4);      // works
| > 
| > ::create is very different from the constructors above.
| 
| Sure, but in this case I get the same results: "c(4L,4L)", right?

Correct.
 
Dirk
2 days later
#
Le 12/01/12 11:29, Gregor Kastner a ?crit :
This should be fixed in rev 3440.

This was due to some compiler ambiguities, so I just added some 
disambiguation.

Romain