Re: [Rcpp-devel] clang does not like lists with a DataFrame inside?

2017-12-05 Thread Ramon Diaz-Uriarte



On Tue, 28-November-2017, at 00:24:33, Dirk Eddelbuettel  
wrote:
> On 28 November 2017 at 00:03, Ramon Diaz-Uriarte wrote:
> | Hi Dirk,
> |
> |
> | On Mon, 27-November-2017, at 14:14:09, Dirk Eddelbuettel  
> wrote:
> | > Ramon,
> | >
> | > On 27 November 2017 at 10:43, Ramon Diaz-Uriarte wrote:
> | > | Dear All,
> | > |
> | > | I am trying to pass to C++ an R list that contains a data frame. Using 
> gcc
> | > | the following
> | > |
> | > | #
> | > |
> | > | #include 
> | > | using namespace Rcpp;
> | > |
> | > | // [[Rcpp::export]]
> | > | void withDF(Rcpp::List bl) {
> | > |   Rcpp::DataFrame df1 = bl["the_df"];
> | >
> | > I think every existing example uses a template when extracting items from 
> a
> | > list as we cannot know at compile time which run-time SEXP we will be 
> handed.
> |
> | Aha, understood. I did not think much about it, tried with gcc, it worked,
> | and then was surprised to see it not work with clang.
>
> These slight differences annoyed me at the beginning, but the advantage of
> getting older is that you just get generally more forgetful.  "Just assume
> nothing works unless you are explicit about it" seems to be my current motto 
> :)

I am going to store this safely to remind myself of the (many) advantages
of no longer being so young ;-)

Best,

R.



>
> as<>() and wrap() are pretty magic.  We get by with fewer very explicit
> statement than we used to years ago, but some remain, notably
>
>   -- return statements better not be compound
>   -- assignment from list or data.frame by name
>   -- [ your issue here, space for rent upon request ]
>
> [...]
>
> | > I don't think so. See eg
> | >
> | > 
> https://github.com/eddelbuettel/rcppexamples/blob/master/src/ListExample.cpp
> |
> | Thanks for that. Bookmarked for future reference :-)
>
> It's old and could be expanded but better than nothing.
>
> Dirk


--
Ramon Diaz-Uriarte
Department of Biochemistry, Lab B-25
Facultad de Medicina
Universidad Autónoma de Madrid
Arzobispo Morcillo, 4
28029 Madrid
Spain

Phone: +34-91-497-2412

Email: rdia...@gmail.com
   ramon.d...@iib.uam.es

http://ligarto.org/rdiaz
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Re: [Rcpp-devel] clang does not like lists with a DataFrame inside?

2017-11-27 Thread Dirk Eddelbuettel

On 28 November 2017 at 00:03, Ramon Diaz-Uriarte wrote:
| Hi Dirk,
| 
| 
| On Mon, 27-November-2017, at 14:14:09, Dirk Eddelbuettel  
wrote:
| > Ramon,
| >
| > On 27 November 2017 at 10:43, Ramon Diaz-Uriarte wrote:
| > | Dear All,
| > |
| > | I am trying to pass to C++ an R list that contains a data frame. Using gcc
| > | the following
| > |
| > | #
| > |
| > | #include 
| > | using namespace Rcpp;
| > |
| > | // [[Rcpp::export]]
| > | void withDF(Rcpp::List bl) {
| > |   Rcpp::DataFrame df1 = bl["the_df"];
| >
| > I think every existing example uses a template when extracting items from a
| > list as we cannot know at compile time which run-time SEXP we will be 
handed.
| 
| Aha, understood. I did not think much about it, tried with gcc, it worked,
| and then was surprised to see it not work with clang.

These slight differences annoyed me at the beginning, but the advantage of
getting older is that you just get generally more forgetful.  "Just assume
nothing works unless you are explicit about it" seems to be my current motto :)

as<>() and wrap() are pretty magic.  We get by with fewer very explicit
statement than we used to years ago, but some remain, notably

  -- return statements better not be compound
  -- assignment from list or data.frame by name
  -- [ your issue here, space for rent upon request ]

[...]

| > I don't think so. See eg
| >
| > https://github.com/eddelbuettel/rcppexamples/blob/master/src/ListExample.cpp
| 
| Thanks for that. Bookmarked for future reference :-)

It's old and could be expanded but better than nothing.

Dirk

-- 
http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


Re: [Rcpp-devel] clang does not like lists with a DataFrame inside?

2017-11-27 Thread Ramon Diaz-Uriarte
Hi Dirk,


On Mon, 27-November-2017, at 14:14:09, Dirk Eddelbuettel  
wrote:
> Ramon,
>
> On 27 November 2017 at 10:43, Ramon Diaz-Uriarte wrote:
> | Dear All,
> |
> | I am trying to pass to C++ an R list that contains a data frame. Using gcc
> | the following
> |
> | #
> |
> | #include 
> | using namespace Rcpp;
> |
> | // [[Rcpp::export]]
> | void withDF(Rcpp::List bl) {
> |   Rcpp::DataFrame df1 = bl["the_df"];
>
> I think every existing example uses a template when extracting items from a
> list as we cannot know at compile time which run-time SEXP we will be handed.

Aha, understood. I did not think much about it, tried with gcc, it worked,
and then was surprised to see it not work with clang.


>
> |   Rcpp::Rcout << " rows are " << df1.size() << std::endl;
> | }
> |
> | 
> |
> | works fine.
> |
> | Using clang (version 3.8 in a system with Debian, but I think same issues
> | in Mac with clang 4) I get
> |
> |
> | f5.cpp:12:19: error: conversion from 'NameProxy' (aka 
> 'generic_name_proxy<19>') to 'Rcpp::DataFrame' (aka
> |   'DataFrame_Impl') is ambiguous
> |   Rcpp::DataFrame df1 = bl["the_df"];
> |   ^ 
> | 
> /home/ramon/Sources/R-3.5.0-73698/library/Rcpp/include/Rcpp/vector/proxy.h:165:3:
>  note: candidate function [with T =
> |   Rcpp::DataFrame_Impl]
> | operator T() const {
> | ^
> | 
> /home/ramon/Sources/R-3.5.0-73698/library/Rcpp/include/Rcpp/DataFrame.h:51:9: 
> note: candidate constructor [with T =
> |   Rcpp::internal::generic_name_proxy<19>]
> | DataFrame_Impl( const T& obj ) ;
> | ^
> | 1 error generated.
> | /home/ramon/Sources/R-3.5.0-73698/etc/Makeconf:166: recipe for target 
> 'f5.o' failed
> | make: *** [f5.o] Error 1
> | Error in sourceCpp("f5.cpp", verbose = TRUE, rebuild = TRUE) :
> |   Error 1 occurred building shared library.
> |
> |
> |
> | Note that the following, treating the data frame as a list, works fine with
> | both gcc and clang
> |
> |
> | #include 
> | using namespace Rcpp;
> |
> | // [[Rcpp::export]]
> | void withList(Rcpp::List bl) {
> |   Rcpp::List df1 = bl["the_df"];
> |   Rcpp::Rcout << " size is " << df1.size() << std::endl;
> |   Rcpp::IntegerVector c1 = df1["first"];
> |   Rcpp::Rcout << " rows are " << c1.size() << std::endl;
> | }
> |
> |
> | Is this bug?
>
> I don't think so. See eg
>
> https://github.com/eddelbuettel/rcppexamples/blob/master/src/ListExample.cpp


Thanks for that. Bookmarked for future reference :-)


Best,


R.


>
> Dirk
>
> |
> | Best,
> |
> |
> | R.
> |
> | --
> | Ramon Diaz-Uriarte
> | Department of Biochemistry, Lab B-25
> | Facultad de Medicina
> | Universidad Autónoma de Madrid
> | Arzobispo Morcillo, 4
> | 28029 Madrid
> | Spain
> |
> | Phone: +34-91-497-2412
> |
> | Email: rdia...@gmail.com
> |ramon.d...@iib.uam.es
> |
> | http://ligarto.org/rdiaz
> | ___
> | Rcpp-devel mailing list
> | Rcpp-devel@lists.r-forge.r-project.org
> | https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


--
Ramon Diaz-Uriarte
Department of Biochemistry, Lab B-25
Facultad de Medicina
Universidad Autónoma de Madrid
Arzobispo Morcillo, 4
28029 Madrid
Spain

Phone: +34-91-497-2412

Email: rdia...@gmail.com
   ramon.d...@iib.uam.es

http://ligarto.org/rdiaz
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Re: [Rcpp-devel] clang does not like lists with a DataFrame inside?

2017-11-27 Thread Dirk Eddelbuettel

Ramon,

On 27 November 2017 at 10:43, Ramon Diaz-Uriarte wrote:
| Dear All,
| 
| I am trying to pass to C++ an R list that contains a data frame. Using gcc
| the following
| 
| #
| 
| #include 
| using namespace Rcpp;
| 
| // [[Rcpp::export]]
| void withDF(Rcpp::List bl) {
|   Rcpp::DataFrame df1 = bl["the_df"];

I think every existing example uses a template when extracting items from a
list as we cannot know at compile time which run-time SEXP we will be handed.

|   Rcpp::Rcout << " rows are " << df1.size() << std::endl;
| }
| 
| 
| 
| works fine.
| 
| Using clang (version 3.8 in a system with Debian, but I think same issues
| in Mac with clang 4) I get
| 
| 
| f5.cpp:12:19: error: conversion from 'NameProxy' (aka 
'generic_name_proxy<19>') to 'Rcpp::DataFrame' (aka
|   'DataFrame_Impl') is ambiguous
|   Rcpp::DataFrame df1 = bl["the_df"];
|   ^ 
| 
/home/ramon/Sources/R-3.5.0-73698/library/Rcpp/include/Rcpp/vector/proxy.h:165:3:
 note: candidate function [with T =
|   Rcpp::DataFrame_Impl]
| operator T() const {
| ^
| /home/ramon/Sources/R-3.5.0-73698/library/Rcpp/include/Rcpp/DataFrame.h:51:9: 
note: candidate constructor [with T =
|   Rcpp::internal::generic_name_proxy<19>]
| DataFrame_Impl( const T& obj ) ;
| ^
| 1 error generated.
| /home/ramon/Sources/R-3.5.0-73698/etc/Makeconf:166: recipe for target 'f5.o' 
failed
| make: *** [f5.o] Error 1
| Error in sourceCpp("f5.cpp", verbose = TRUE, rebuild = TRUE) :
|   Error 1 occurred building shared library.
| 
| 
| 
| Note that the following, treating the data frame as a list, works fine with
| both gcc and clang
| 
| 
| #include 
| using namespace Rcpp;
| 
| // [[Rcpp::export]]
| void withList(Rcpp::List bl) {
|   Rcpp::List df1 = bl["the_df"];
|   Rcpp::Rcout << " size is " << df1.size() << std::endl;
|   Rcpp::IntegerVector c1 = df1["first"];
|   Rcpp::Rcout << " rows are " << c1.size() << std::endl;
| }
| 
| 
| Is this bug?

I don't think so. See eg

https://github.com/eddelbuettel/rcppexamples/blob/master/src/ListExample.cpp

Dirk

| 
| Best,
| 
| 
| R.
| 
| --
| Ramon Diaz-Uriarte
| Department of Biochemistry, Lab B-25
| Facultad de Medicina
| Universidad Autónoma de Madrid
| Arzobispo Morcillo, 4
| 28029 Madrid
| Spain
| 
| Phone: +34-91-497-2412
| 
| Email: rdia...@gmail.com
|ramon.d...@iib.uam.es
| 
| http://ligarto.org/rdiaz
| ___
| Rcpp-devel mailing list
| Rcpp-devel@lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
-- 
http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel