Discussion:
[Rcpp-devel] questions Rcpp
Mounia ZAOUCHE
2018-09-13 11:09:32 UTC
Permalink
Dear all.

I write C++ programs and I'm currently trying to interface them with R.

I have two issues :

Is it possible to interface a function which has an argument that is a pointer (standing for an array) ?

I also wrote a function whose aim is to allocate (and fill) an array of values. In this purpose, this function takes as an argument the address of the array to be allocated and is thus typed as a pointer of pointer.
Is it possible to handle such a type and to allocate the required memory inside this function interfaced in R?

Thank you in advance.

Mounia Zaouche.
Qiang Kou
2018-09-13 15:51:00 UTC
Permalink
Hi, Mounia,

In Rcpp, using std::vector is preferred.

It is still possible to use pointers, however, I am afraid you need to
write your "as" and "wrap" by yourself. You can find how to develop them in
our documents.

Best,

Qiang Kou

On Thu, Sep 13, 2018 at 4:15 AM Mounia ZAOUCHE <
Post by Mounia ZAOUCHE
Dear all.
I write C++ programs and I'm currently trying to interface them with R.
Is it possible to interface a function which has an argument that is a
pointer (standing for an array) ?
I also wrote a function whose aim is to allocate (and fill) an array of
values. In this purpose, this function takes as an argument the address of
the array to be allocated and is thus typed as a pointer of pointer.
Is it possible to handle such a type and to allocate the required memory
inside this function interfaced in R?
Thank you in advance.
Mounia Zaouche.
_______________________________________________
Rcpp-devel mailing list
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
Dirk Eddelbuettel
2018-09-13 20:55:58 UTC
Permalink
On 13 September 2018 at 08:51, Qiang Kou wrote:
| Hi, Mounia,
|
| In Rcpp, using std::vector is preferred.

Building on what Qiang said: If your array is a simple double[] then you can
switch to std::vector<double> easily as aligning your array with the internal
array. (Ditto for most other arrays of base types.)

Or conversely, your can use Rcpp and transfer data from R down to C++ code
using a std::vector<double> and then access the address of the initial
element for your pointer. But the better approach is to use std::vector<>
(Or our Rcpp::NumericVector).

One reason is that Rcpp uses the .Call() interface to R, and it does _not_
support plain C pointers. Only the older (and not recommended anymore) .C()
interface does. But then you have to give up all of Rcpp as well ...

| It is still possible to use pointers, however, I am afraid you need to
| write your "as" and "wrap" by yourself. You can find how to develop them in
| our documents.

And as<>() and wrap() are really intended for more complex data structures
and not for pointers to atomistic C types. And yes, you would have work to do
for new types.

Hope this helps, Dirk

| Best,
|
| Qiang Kou
|
| On Thu, Sep 13, 2018 at 4:15 AM Mounia ZAOUCHE <
| ***@agroparistech.fr> wrote:
|
| >
| > Dear all.
| >
| > I write C++ programs and I'm currently trying to interface them with R.
| >
| > I have two issues :
| >
| > Is it possible to interface a function which has an argument that is a
| > pointer (standing for an array) ?
| >
| > I also wrote a function whose aim is to allocate (and fill) an array of
| > values. In this purpose, this function takes as an argument the address of
| > the array to be allocated and is thus typed as a pointer of pointer.
| > Is it possible to handle such a type and to allocate the required memory
| > inside this function interfaced in R?
| >
| > Thank you in advance.
| >
| > Mounia Zaouche.
| >
| > _______________________________________________
| > Rcpp-devel mailing list
| > Rcpp-***@lists.r-forge.r-project.org
| > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-***@lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
--
http://dirk.eddelbuettel.com | @eddelbuettel | ***@debian.org
Mounia ZAOUCHE
2018-09-14 13:25:40 UTC
Permalink
Thank you very much for your answers.
Actually, it is really helpful.
Best,

Mounia


De: "edd" <***@debian.org>
À: "Qiang Kou" <***@qkou.info>
Cc: "mounia zaouche" <***@agroparistech.fr>, "rcpp-devel" <rcpp-***@lists.r-forge.r-project.org>
Envoyé: Jeudi 13 Septembre 2018 22:55:58
Objet: Re: [Rcpp-devel] questions Rcpp

On 13 September 2018 at 08:51, Qiang Kou wrote:
| Hi, Mounia,
|
| In Rcpp, using std::vector is preferred.

Building on what Qiang said: If your array is a simple double[] then you can
switch to std::vector<double> easily as aligning your array with the internal
array. (Ditto for most other arrays of base types.)

Or conversely, your can use Rcpp and transfer data from R down to C++ code
using a std::vector<double> and then access the address of the initial
element for your pointer. But the better approach is to use std::vector<>
(Or our Rcpp::NumericVector).

One reason is that Rcpp uses the .Call() interface to R, and it does _not_
support plain C pointers. Only the older (and not recommended anymore) .C()
interface does. But then you have to give up all of Rcpp as well ...

| It is still possible to use pointers, however, I am afraid you need to
| write your "as" and "wrap" by yourself. You can find how to develop them in
| our documents.

And as<>() and wrap() are really intended for more complex data structures
and not for pointers to atomistic C types. And yes, you would have work to do
for new types.

Hope this helps, Dirk

| Best,
|
| Qiang Kou
|
| On Thu, Sep 13, 2018 at 4:15 AM Mounia ZAOUCHE <
| ***@agroparistech.fr> wrote:
|
| >
| > Dear all.
| >
| > I write C++ programs and I'm currently trying to interface them with R.
| >
| > I have two issues :
| >
| > Is it possible to interface a function which has an argument that is a
| > pointer (standing for an array) ?
| >
| > I also wrote a function whose aim is to allocate (and fill) an array of
| > values. In this purpose, this function takes as an argument the address of
| > the array to be allocated and is thus typed as a pointer of pointer.
| > Is it possible to handle such a type and to allocate the required memory
| > inside this function interfaced in R?
| >
| > Thank you in advance.
| >
| > Mounia Zaouche.
| >
| > _______________________________________________
| > Rcpp-devel mailing list
| > Rcpp-***@lists.r-forge.r-project.org
| > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-***@lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
--
http://dirk.eddelbuettel.com | @eddelbuettel | ***@debian.org
Dale Smith
2018-09-14 14:58:36 UTC
Permalink
Hello all,

While I’m not very active in R at the moment, I’m still here.

Dirk ran a class in Rcpp in the fall of 2011. I’ve not heard of any classes since, but it strikes me that there are enough people familiar with Rcpp to run regional classes. This would make travel easier. Or, core members of this group could use Udemy. Actually, Udemy would reach more people.

I’m available for volunteer efforts to a limited extent.

Thanks,
Dale Smith
***@mindspring.com
917-691-1791

Note: All times are Eastern.

See my calendar to book a time to speak with me https://calendly.com/dtsmith2001
Dirk Eddelbuettel
2018-09-14 15:14:28 UTC
Permalink
On 14 September 2018 at 10:58, Dale Smith wrote:
| Hello all,
|
| While I’m not very active in R at the moment, I’m still here.
|
| Dirk ran a class in Rcpp in the fall of 2011.

That was in SF. We also did NY a few years later.

| I’ve not heard of any classes since, but it strikes me that there are
| enough people familiar with Rcpp to run regional classes. This would make
| travel easier. Or, core members of this group could use Udemy. Actually,
| Udemy would reach more people.

I think there is one in the making at datacamp. They had asked me a few
times, I never had enough time -- but I believe Romain worked with them and
something outght to be ready at some point.

I have taught twice at Uni Zuerich (giving a two-day course) in the years
that useR! was in Europe.

I am not aware of anything else that is recurrent but happy to index or
document something.

| I’m available for volunteer efforts to a limited extent.

Good to know!

Cheers, Dirk
--
http://dirk.eddelbuettel.com | @eddelbuettel | ***@debian.org
Continue reading on narkive:
Loading...