私はRcppを初めて使っています。問題の長短は、ポインタを生成するオブジェクトがあり、そのポインタをRに戻すことです。Rcppでsize_tの折り返しを返します。
ポインタをsize_t
にキャストすると必要な精度が維持されていますが、 wrap
でそれを返すことができます。
以下のコードでは、unsigned long int
を返すだけでコンパイルできますが、他はエラーが発生しますが、これはスペースのためにここには含まれません。私のオブジェクトでは、unsigned long int
にキャストすると、精度が失われたためにコンパイラが失敗します(最初のブロックにはすべてコメントアウトされています)。
size_t
を使用すると、このタイプのオブジェクトに対してwrap
テンプレートを作成する代わりの方法を避けるために十分です。
私はchangelogを確認しました。それはsize_tがサポートされているようです。 overviewはsize_t
のためのwrap
のサポートも示唆しています。
#include <Rcpp.h>
#include <iostream>
using namespace Rcpp;
using namespace std;
extern "C" SEXP attempt()
{
// this block if uncommented gives compile error that converting a pointer to unsigned long int loses precision
// also, wrapping the pointer &f causes a compilation error
//int f = 314;
//unsigned long int theVar_longint = (unsigned long int) &f;
//cout << "pointer: " << &f << endl;
//return(wrap(&f));
// This block makes an arbitrary value into a size_t, unsigned long int and unsigned long long int
size_t theVar_sizet = (size_t) 383762523;
unsigned long int theVar_longint = (unsigned long int) 383762523;
unsigned long long int theVar_longlongint = (unsigned long long int) 383762523;
// prints the results
cout << "size_t: " << theVar_sizet << endl;
cout << "longint: " << theVar_longint << endl;
cout << "longlongint: " << theVar_longlongint << endl;
// only the first line returns properly, the others cause errors in compilation
return(wrap(theVar_longint));
//return(wrap(theVar_longlongint));
//return(wrap(theVar_sizet));
}
R_xlen_tを試しましたか? –