Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem when I use the RcppArmadillo with the C++11 #23

Closed
guokai8 opened this issue Oct 13, 2014 · 1 comment
Closed

Problem when I use the RcppArmadillo with the C++11 #23

guokai8 opened this issue Oct 13, 2014 · 1 comment

Comments

@guokai8
Copy link

guokai8 commented Oct 13, 2014

When I use the RcppArmadillo I must add the "Sys.setenv("PKG_CXXFLAGS"="-std=c++11")" in the .cpp script before I compiled, and I could not just add the " // [[Rcpp::plugins(cpp11)]]" in the script to enable C++11. Here is the sessionInfo

sessionInfo()
R version 3.1.1 (2014-07-10)
Platform: x86_64-apple-darwin10.8.0 (64-bit)

locale:
[1] zh_CN.UTF-8/zh_CN.UTF-8/zh_CN.UTF-8/C/zh_CN.UTF-8/zh_CN.UTF-8

attached base packages:
[1] stats graphics grDevices utils datasets compiler methods
[8] base

other attached packages:
[1] dplyr_0.2 reshape2_1.4 Rcpp_0.11.3 plyr_1.8.1 pipeR_0.3-1

loaded via a namespace (and not attached):
[1] assertthat_0.1 parallel_3.1.1 stringr_0.6.2 tools_3.1.1

I wonder how could I just add the "// [[Rcpp::plugins(cpp11)]]" in the script or when I using the inline package?

@eddelbuettel
Copy link
Member

This works for me

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

// [[Rcpp::depends(RcppArmadillo)]]

#include <RcppArmadillo.h>

// [[Rcpp::export]]
arma::vec foo() {
    arma::vec x = { 1.1, 2.2 };
    return x;
}

via

R> sourceCpp("/tmp/arma11.cpp")
R> foo()
     [,1]
[1,]  1.1
[2,]  2.2
R> 

so I see no issue here.

In packages, you can use src/Makevars* (or DESCRIPTION). In files you have the plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants