[Rcpp-devel] Problem with NumericVector or NumericMatrix

Vaidas Zemlys mpiktas at gmail.com
Tue Mar 1 10:41:57 CET 2016


Hi,

You do not need to use evalCpp. After you use Rcpp::sourceCpp, you can use timesTwo as a normal R function, i.e. you do not need evalCpp. This is quite clearly demonstrated in Rstudio template for C++ code.

Vaidotas

> Le 1 mars 2016 à 11:29, Philippe Huber <ph_geneve at hotmail.com> a écrit :
> 
> Hi,
> 
> I am starting to use Rcpp and got into some issues with basic examples.
> 
> I am trying to run this:
> 
> #include <Rcpp.h>
> 
> using namespace Rcpp;
> 
> // [[Rcpp::export]]
> NumericVector timesTwo(NumericVector x) {
>   return x * 2;
> }
> 
> It works fine when I use it like:
> > evalCpp(timesTwo(2))
> [1] 4
> 
> But as soon as I use a vector, I get some weird error message:
> 
> > v=as.vector(c(2,2))
> > evalCpp(timesTwo(v))
> g++ -m64 -I"C:/PROGRA~1/R/R-32~1.3/include" -DNDEBUG     -I"C:/Users/Hubert/Documents/R/win-library/3.2/Rcpp/include" -I"C:/Users/Hubert/AppData/Local/Temp/RtmpaujML3"  -I"d:/RCompile/r-compiling/local/local323/include"     -O2 -Wall  -mtune=core2 -c file33c329d4fd2.cpp -o file33c329d4fd2.o
> file33c329d4fd2.cpp: In function 'SEXPREC* get_value()':
> file33c329d4fd2.cpp:7:6: error: redefinition of 'SEXPREC* get_value()'
> file33c329d4fd2.cpp:6:6: error: 'SEXPREC* get_value()' previously defined here
> make: *** [file33c329d4fd2.o] Error 1
> Warning message:
> l'exécution de la commande 'make -f "C:/PROGRA~1/R/R-32~1.3/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-32~1.3/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="sourceCpp_10.dll" WIN=64 TCLBIN=64 OBJECTS="file33c329d4fd2.o"' renvoie un statut 2 
> Error in sourceCpp(code = code, env = env, rebuild = rebuild, showOutput = showOutput,  : 
>   Error 1 occurred building shared library.
> 
> I tried to find a solution but got nothing.
> 
> Can someone please help me?
> 
> Thanks
> 
> Philippe
> 
> 
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org <mailto:Rcpp-devel at lists.r-forge.r-project.org>
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel <https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20160301/7b0529e3/attachment-0001.html>


More information about the Rcpp-devel mailing list