Soren,
Thanks for the insight. For other readers possibly struggling with call by
reference, the following code works as expected, i.e., x is changed to c(1,
2).
#include
using namespace Rcpp;
// [[Rcpp::export]]
void absC(NumericVector & x) {
int n = x.size();
for (int i = 0; i < n; ++i) {
if
Just a follow up on "copying": If you copying": If you do
#include
using namespace Rcpp;
// [[Rcpp::export]]
void absC(NumericVector & x) {
if (x[0] < 0)
x = -x;
}
/*** R
y <- -1L
absC(y)
y
*/
you'll get
> y <- -1L
> absC(y)
> y
[1] -1
and that is because an IntegerVector is provided but
Rcpp 0.12.0 came out on Saturday, and I wrote a short blog which I expected
to be mostly ignored on the weekend. I then forgot to mention this here.
A short blog post about it is at
http://dirk.eddelbuettel.com/blog/
http://dirk.eddelbuettel.com/blog/2015/07/25#rcpp_0.12.0
and includ
On 28 July 2015 at 17:53, Rguy wrote:
| I attempted to implement the call by reference example on page 200 of Seamless
| R and C++, as follows:
|
| #include
| using namespace Rcpp;
|
| // [[Rcpp::export]]
| void absC(double & x) {
| if (x < 0) x = -x;
| }
|
| /*** R
| x = -1
| absC(x)
| x
| */
I attempted to implement the call by reference example on page 200 of
Seamless R and C++, as follows:
#include
using namespace Rcpp;
// [[Rcpp::export]]
void absC(double & x) {
if (x < 0) x = -x;
}
/*** R
x = -1
absC(x)
x
*/
Unfortunately, x remains equal to -1.
Platforms: Windows 7, "R versi
Dear list,
As a follow-up to last week's discussion, the simplest solution is
indeed inlining.
You can define your wrapper functions in a header, myPackage.h,
containing inline function definitions rather than declarations:
namespace Rcpp {
template <> inline myClass as(SEXP foo){
/
Wow - that is of course the best solution!
Thanks for the detailed instructions - worked like a charm.
I was not aware of these PPAs, but they are really helpful for my small,
outdated, and virtual server ;-)
Cheers,
Felix
On 27 Jul 2015, at 19:37, Dirk Eddelbuettel wrote:
On 27 July 2015