Discussion:
[Rcpp-devel] Strange error
Tim Keitt
2018-03-08 17:52:18 UTC
Permalink
I must be going blind or something because I cannot see the error here.

sourceCpp(code = '
// [[Rcpp::depends(BH)]]
// [[Rcpp::plugins(cpp11)]]

#include <vector>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>

using key_type = boost::geometry::model::d2::point_xy<double>;
using range_type = std::vector<key_type>;

range_type data;
data.reserve(1e6);

for (int i = 0; i != 1e6; ++i)
data.emplace_back(R::runif(), R::runif());
')

I get:

filefc2f3edf6585.cpp:13:1: error: unknown type name 'data'
data.reserve(1e6);
^
filefc2f3edf6585.cpp:13:5: error: cannot use dot operator on a type
data.reserve(1e6);
^
filefc2f3edf6585.cpp:15:1: error: expected unqualified-id
for (int i = 0; i != 1e6; ++i)
^
3 errors generated.
make: *** [filefc2f3edf6585.o] Error 1

Must be something trivial I am not seeing. Anyone else see something I'm
doing wrong?

THK

http://www.keittlab.org/
Dirk Eddelbuettel
2018-03-08 18:20:08 UTC
Permalink
Tim,

Three distinct errors:

- no wrapping function, so sourceCpp() was the wrong paradigm
- no inclusion of Rcpp.h so types unknown (agem)
- wrong calling convention for runif(), cannot be empty.

The following compiles, it may still be nonsensical.

Dirk


// [[Rcpp::depends(BH)]]
// [[Rcpp::plugins(cpp11)]]

#include <Rcpp.h>

#include <vector>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>

using key_type = boost::geometry::model::d2::point_xy<double>;
using range_type = std::vector<key_type>;

// [[Rcpp::export]]
void foo() {
range_type data;
data.reserve(1e6);

for (int i = 0; i != 1e6; ++i)
data.emplace_back(R::runif(0,1), R::runif(0,1));
}
--
http://dirk.eddelbuettel.com | @eddelbuettel | ***@debian.org
Tim Keitt
2018-03-08 20:28:15 UTC
Permalink
Ha. That's simultaneously kinda funny and kinda painful. It was embedded
into an Rmd Rcpp chunk and I forgot the C++ entry point... sigh.

THK

http://www.keittlab.org/
Post by Dirk Eddelbuettel
Tim,
- no wrapping function, so sourceCpp() was the wrong paradigm
- no inclusion of Rcpp.h so types unknown (agem)
- wrong calling convention for runif(), cannot be empty.
The following compiles, it may still be nonsensical.
Dirk
// [[Rcpp::depends(BH)]]
// [[Rcpp::plugins(cpp11)]]
#include <Rcpp.h>
#include <vector>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
using key_type = boost::geometry::model::d2::point_xy<double>;
using range_type = std::vector<key_type>;
// [[Rcpp::export]]
void foo() {
range_type data;
data.reserve(1e6);
for (int i = 0; i != 1e6; ++i)
data.emplace_back(R::runif(0,1), R::runif(0,1));
}
--
Continue reading on narkive:
Loading...