[Rcpp-devel] ‘_’ was not declared in th is scope
Dirk Eddelbuettel
edd at debian.org
Sun May 29 20:56:57 CEST 2011
Hi Vincent,
On 29 May 2011 at 14:45, Vincent Arel wrote:
| Hi all,
|
| Apologies for the newbie question, but I am trying to build my first R
No apologies needed -- we do appreciate that you ask here.
| package with a Rcpp function, and I am running into some issues with
| Sugar expressions not compiling. I tried to model my package on one of
| the RcppExamples, and put the code pasted below in the file
| /src/ar1.cpp. There's also an R function in /R/ar1.R with a simple
| .Call to the c++ function. I build the package, but when I try to
| install it from source using 'R CMD INSTALL mypackage.tar.gz', I get
| the error pasted below. But the example works fine with the inline
| package.
There is a not-so-obvious side-effect of inline's cxxfunction: it adds
using namespace Rcpp;
making all Rcpp symbols public. That is how '_' works with it.
| I am running R 2.12 on Ubuntu 11.04.
|
| Thanks for your time!
|
| Vincent
|
| ### Error:
|
| ar1.cpp: In function ‘SEXPREC* ar1(SEXPREC*, SEXPREC*)’:
| ar1.cpp:8:11: error: ‘_’ was not declared in this scope
| make: *** [ar1.o] Error 1
| ERROR: compilation failed for package ‘mypackage’
You need to either be explicit:
xbem(i,Rcpp::_) = xbem(i-1,Rcpp::_) * gv[0] + xbem(i,Rcpp::_);
or add the 'using namespace Rcpp', or maybe compromise and just add
using namespace Rcpp::_;
which makes '_' visible but requires you to explicitlu reference the rest as
you do below.
Hope this helps, Dirk
|
| ### Code:
|
| #include "Rcpp.h"
|
| RcppExport SEXP ar1(SEXP xbe, SEXP g){
| Rcpp::NumericMatrix xbem(xbe);
| int nrows = xbem.nrow();
| Rcpp::NumericVector gv(g);
| for (int i = 1; i < nrows; i++) {
| xbem(i,_) = xbem(i-1,_) * gv[0] + xbem(i,_);
| }
| return xbem;
| }
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
--
Gauss once played himself in a zero-sum game and won $50.
-- #11 at http://www.gaussfacts.com
More information about the Rcpp-devel
mailing list