Skip to content

[Rcpp-devel] Bug with table sugar and NumericVector in Rcpp 0.10.3

11 messages · Romain Francois, Dirk Eddelbuettel, Kevin Ushey

#
Hi guys,

When I attempt to 'sourceCpp' the following code, the R session crashes:

#include <Rcpp.h>
using namespace Rcpp;

// [[Rcpp::export]]
IntegerVector counts(NumericVector x) {
  return table(x);
}

The same code worked in Rcpp 0.10.2.

A hint to the error comes if I try to compile a package with that source
code in a .cpp file: I get the error, when attempting to load the package:

dlopen(/Library/Frameworks/R.framework/Versions/2.15/Resources/library/anRpackage/libs/x86_64/anRpackage.so,
6): Symbol not found:
__ZN4Rcpp8internal16coerce_to_stringILi14EEEPKcNS_6traits12storage_typeIXT_EE4typeE
  Referenced from:
/Library/Frameworks/R.framework/Versions/2.15/Resources/library/anRpackage/libs/x86_64/anRpackage.so
  Expected in: flat namespace
 in
/Library/Frameworks/R.framework/Versions/2.15/Resources/library/anRpackage/libs/x86_64/anRpackage.so

This is with R 2.15.3 on Mac OSX 10.8.3.

-----

In addition, if I attempt to compile Rcpp from source (with gcc 4.8) I get
the following warnings:
Installing package(s) into
?/Library/Frameworks/R.framework/Versions/2.15/Resources/library?
(as ?lib? is unspecified)
trying URL 'http://cran.rstudio.com/src/contrib/Rcpp_0.10.3.tar.gz'
Content type 'application/x-gzip' length 2395986 bytes (2.3 Mb)
opened URL
==================================================
downloaded 2.3 Mb

* installing *source* package ?Rcpp? ...
** package ?Rcpp? successfully unpacked and MD5 sums checked
** libs
*** arch - x86_64
g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include
-I/Library/Frameworks/R.framework/Resources/include/x86_64 -DNDEBUG
-I../inst/include/ -I/usr/local/include    -fPIC  -g -O3 -Wall -pedantic -c
Date.cpp -o Date.o
g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include
-I/Library/Frameworks/R.framework/Resources/include/x86_64 -DNDEBUG
-I../inst/include/ -I/usr/local/include    -fPIC  -g -O3 -Wall -pedantic -c
Module.cpp -o Module.o
In file included from ../inst/include/Rcpp/Module.h:352:0,
                 from ../inst/include/Rcpp.h:63,
                 from Module.cpp:22:
../inst/include/Rcpp/module/class.h: In member function
?Rcpp::class_<Class>::self& Rcpp::class_<Class>::derives(const char*)?:
../inst/include/Rcpp/module/class.h:495:56: warning: typedef
?parent_prop_class? locally defined but not used [-Wunused-local-typedefs]
             typedef typename parent_class_::prop_class parent_prop_class ;
<snip, snip>

although the package does install successfully. Not sure if it's related or
not.

Thanks,
-Kevin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130328/adc37496/attachment.html>
#
Hello,

This is related to this change:

2013-01-15  Dirk Eddelbuettel  <edd at debian.org>

	* src/api.cpp (Rcpp): Commented-out coerce_to_string() for real and
	complex arguments as R-devel (as of today) dislikes use of non-API
	functions Rf_EncodeComplex?, ?Rf_EncodeReal?, ?Rf_formatComplex?

So maybe Dirk has a plan to fix it.

Romain

Le 2013-03-29 07:27, Kevin Ushey a ?crit?:
#
On 29 March 2013 at 09:11, romain at r-enthusiasts.com wrote:
| 
| Hello,
| 
| This is related to this change:
| 
| 2013-01-15  Dirk Eddelbuettel  <edd at debian.org>
| 
| 	* src/api.cpp (Rcpp): Commented-out coerce_to_string() for real and
| 	complex arguments as R-devel (as of today) dislikes use of non-API
| 	functions Rf_EncodeComplex?, ?Rf_EncodeReal?, ?Rf_formatComplex?
| 
| So maybe Dirk has a plan to fix it.

I do not. I had a choice to make between 

  a) keeping Rcpp on CRAN

  b) keeping that feature.

I chose a). 

If someone needs b), patches are always welcome.  It should not be hard to
support conversion to character.

It wasn't the first time, and likely not the last time, that I had to curtail
code of yours to make a release possible.  Such is life.  

You write a lot of great code, but some violates some CRAN guidelines
(which unfortunately change over time) and some break other things. So
sometimes we do need to revert. 

Dirk
 
| Romain
| 
| Le 2013-03-29 07:27, Kevin Ushey a ?crit?:
| > Hi guys,
| >
| > When I attempt to 'sourceCpp' the following code, the R session
| > crashes:
| >
| > #include <Rcpp.h>
| > using namespace Rcpp;
| >
| > // [[Rcpp::export]]
| > IntegerVector counts(NumericVector x) {
| > ? return table(x);
| > }
| >
| > The same code worked in Rcpp 0.10.2.
| >
| > A hint to the error comes if I try to compile a package with that
| > source code in a .cpp file: I get the error, when attempting to load
| > the package:
| > 
| > dlopen(/Library/Frameworks/R.framework/Versions/2.15/Resources/library/anRpackage/libs/x86_64/anRpackage.so,
| > 6): Symbol not found:
| > 
| > __ZN4Rcpp8internal16coerce_to_stringILi14EEEPKcNS_6traits12storage_typeIXT_EE4typeE
| >  ? Referenced from:
| > 
| > /Library/Frameworks/R.framework/Versions/2.15/Resources/library/anRpackage/libs/x86_64/anRpackage.so
| > ? Expected in: flat namespace
| > ?in
| > 
| > /Library/Frameworks/R.framework/Versions/2.15/Resources/library/anRpackage/libs/x86_64/anRpackage.so
| >
| > This is with R 2.15.3 on Mac OSX 10.8.3.
| >
| > -----
| >
| > In addition, if I attempt to compile Rcpp from source (with gcc 4.8) 
| > I
| > get the following warnings:
| >
| >> install.packages("Rcpp", type="source",
| > INSTALL_opts="--no-multiarch")
| > Installing package(s) into
| > ?/Library/Frameworks/R.framework/Versions/2.15/Resources/library?
| > (as ?lib? is unspecified)
| > trying URL 'http://cran.rstudio.com/src/contrib/Rcpp_0.10.3.tar.gz
| > [1]'
| > Content type 'application/x-gzip' length 2395986 bytes (2.3 Mb)
| > opened URL
| > ==================================================
| > downloaded 2.3 Mb
| >
| > * installing *source* package ?Rcpp? ...
| > ** package ?Rcpp? successfully unpacked and MD5 sums checked
| > ** libs
| > *** arch - x86_64
| > g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include
| > -I/Library/Frameworks/R.framework/Resources/include/x86_64 -DNDEBUG
| > -I../inst/include/ -I/usr/local/include ? ?-fPIC ?-g -O3 -Wall
| > -pedantic -c Date.cpp -o Date.o
| > g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include
| > -I/Library/Frameworks/R.framework/Resources/include/x86_64 -DNDEBUG
| > -I../inst/include/ -I/usr/local/include ? ?-fPIC ?-g -O3 -Wall
| > -pedantic -c Module.cpp -o Module.o
| > In file included from ../inst/include/Rcpp/Module.h:352:0,
| > ? ? ? ? ? ? ? ? ?from ../inst/include/Rcpp.h:63,
| > ? ? ? ? ? ? ? ? ?from Module.cpp:22:
| > ../inst/include/Rcpp/module/class.h: In member function
| > ?Rcpp::class_<Class>::self& Rcpp::class_<Class>::derives(const
| > char*)?:
| > ../inst/include/Rcpp/module/class.h:495:56: warning: typedef
| > ?parent_prop_class? locally defined but not used
| > [-Wunused-local-typedefs]
| > ? ? ? ? ? ? ?typedef typename parent_class_::prop_class
| > parent_prop_class ;
| > <snip, snip>
| >
| > although the package does install successfully. Not sure if it's
| > related or not.
| >
| > Thanks,
| > -Kevin
| >
| > Links:
| > ------
| > [1] http://cran.rstudio.com/src/contrib/Rcpp_0.10.3.tar.gz
| 
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
#
Le 2013-03-29 14:31, Dirk Eddelbuettel a ?crit?:
Fine. So I'll fix it.
#
On 29 March 2013 at 15:24, romain at r-enthusiasts.com wrote:
| Le 2013-03-29 14:31, Dirk Eddelbuettel a ?crit?:
| > On 29 March 2013 at 09:11, romain at r-enthusiasts.com wrote:
| > |
| > | Hello,
| > |
| > | This is related to this change:
| > |
| > | 2013-01-15  Dirk Eddelbuettel  <edd at debian.org>
| > |
| > | 	* src/api.cpp (Rcpp): Commented-out coerce_to_string() for real 
| > and
| > | 	complex arguments as R-devel (as of today) dislikes use of non-API
| > | 	functions Rf_EncodeComplex?, ?Rf_EncodeReal?, ?Rf_formatComplex?
| > |
| > | So maybe Dirk has a plan to fix it.
| >
| > I do not.
| 
| Fine. So I'll fix it.

Hold on. 

I am in the middle of it. I do have a poor replacementment for EncodeReal,
and am about to test one for complex. Will post soon.

Am not covering scientific notation at this point.

Dirk

 
| > I had a choice to make between
| >
| >   a) keeping Rcpp on CRAN
| >
| >   b) keeping that feature.
| >
| > I chose a).
| >
| > If someone needs b), patches are always welcome.  It should not be 
| > hard to
| > support conversion to character.
| >
| > It wasn't the first time, and likely not the last time, that I had to 
| > curtail
| > code of yours to make a release possible.  Such is life.
| >
| > You write a lot of great code, but some violates some CRAN guidelines
| > (which unfortunately change over time) and some break other things. 
| > So
| > sometimes we do need to revert.
| >
| > Dirk
| >
| > | Romain
| > |
| > | Le 2013-03-29 07:27, Kevin Ushey a ?crit?:
| > | > Hi guys,
| > | >
| > | > When I attempt to 'sourceCpp' the following code, the R session
| > | > crashes:
| > | >
| > | > #include <Rcpp.h>
| > | > using namespace Rcpp;
| > | >
| > | > // [[Rcpp::export]]
| > | > IntegerVector counts(NumericVector x) {
| > | > ? return table(x);
| > | > }
| > | >
| > | > The same code worked in Rcpp 0.10.2.
| > | >
| > | > A hint to the error comes if I try to compile a package with that
| > | > source code in a .cpp file: I get the error, when attempting to 
| > load
| > | > the package:
| > | >
| > | >
| > 
| > dlopen(/Library/Frameworks/R.framework/Versions/2.15/Resources/library/anRpackage/libs/x86_64/anRpackage.so,
| > | > 6): Symbol not found:
| > | >
| > | >
| > 
| > __ZN4Rcpp8internal16coerce_to_stringILi14EEEPKcNS_6traits12storage_typeIXT_EE4typeE
| > | >  ? Referenced from:
| > | >
| > | >
| > 
| > /Library/Frameworks/R.framework/Versions/2.15/Resources/library/anRpackage/libs/x86_64/anRpackage.so
| > | > ? Expected in: flat namespace
| > | > ?in
| > | >
| > | >
| > 
| > /Library/Frameworks/R.framework/Versions/2.15/Resources/library/anRpackage/libs/x86_64/anRpackage.so
| > | >
| > | > This is with R 2.15.3 on Mac OSX 10.8.3.
| > | >
| > | > -----
| > | >
| > | > In addition, if I attempt to compile Rcpp from source (with gcc 
| > 4.8)
| > | > I
| > | > get the following warnings:
| > | >
| > | >> install.packages("Rcpp", type="source",
| > | > INSTALL_opts="--no-multiarch")
| > | > Installing package(s) into
| > | > ?/Library/Frameworks/R.framework/Versions/2.15/Resources/library?
| > | > (as ?lib? is unspecified)
| > | > trying URL 
| > 'http://cran.rstudio.com/src/contrib/Rcpp_0.10.3.tar.gz
| > | > [1]'
| > | > Content type 'application/x-gzip' length 2395986 bytes (2.3 Mb)
| > | > opened URL
| > | > ==================================================
| > | > downloaded 2.3 Mb
| > | >
| > | > * installing *source* package ?Rcpp? ...
| > | > ** package ?Rcpp? successfully unpacked and MD5 sums checked
| > | > ** libs
| > | > *** arch - x86_64
| > | > g++ -arch x86_64 
| > -I/Library/Frameworks/R.framework/Resources/include
| > | > -I/Library/Frameworks/R.framework/Resources/include/x86_64 
| > -DNDEBUG
| > | > -I../inst/include/ -I/usr/local/include ? ?-fPIC ?-g -O3 -Wall
| > | > -pedantic -c Date.cpp -o Date.o
| > | > g++ -arch x86_64 
| > -I/Library/Frameworks/R.framework/Resources/include
| > | > -I/Library/Frameworks/R.framework/Resources/include/x86_64 
| > -DNDEBUG
| > | > -I../inst/include/ -I/usr/local/include ? ?-fPIC ?-g -O3 -Wall
| > | > -pedantic -c Module.cpp -o Module.o
| > | > In file included from ../inst/include/Rcpp/Module.h:352:0,
| > | > ? ? ? ? ? ? ? ? ?from ../inst/include/Rcpp.h:63,
| > | > ? ? ? ? ? ? ? ? ?from Module.cpp:22:
| > | > ../inst/include/Rcpp/module/class.h: In member function
| > | > ?Rcpp::class_<Class>::self& Rcpp::class_<Class>::derives(const
| > | > char*)?:
| > | > ../inst/include/Rcpp/module/class.h:495:56: warning: typedef
| > | > ?parent_prop_class? locally defined but not used
| > | > [-Wunused-local-typedefs]
| > | > ? ? ? ? ? ? ?typedef typename parent_class_::prop_class
| > | > parent_prop_class ;
| > | > <snip, snip>
| > | >
| > | > although the package does install successfully. Not sure if it's
| > | > related or not.
| > | >
| > | > Thanks,
| > | > -Kevin
| > | >
| > | > Links:
| > | > ------
| > | > [1] http://cran.rstudio.com/src/contrib/Rcpp_0.10.3.tar.gz
| > |
| > | _______________________________________________
| > | Rcpp-devel mailing list
| > | Rcpp-devel at lists.r-forge.r-project.org
| > | 
| > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
|
#
On 29 March 2013 at 09:40, Dirk Eddelbuettel wrote:
|
| On 29 March 2013 at 15:24, romain at r-enthusiasts.com wrote:
| | Le 2013-03-29 14:31, Dirk Eddelbuettel a ?crit?:
| | > On 29 March 2013 at 09:11, romain at r-enthusiasts.com wrote:
| | > |
| | > | Hello,
| | > |
| | > | This is related to this change:
| | > |
| | > | 2013-01-15  Dirk Eddelbuettel  <edd at debian.org>
| | > |
| | > | 	* src/api.cpp (Rcpp): Commented-out coerce_to_string() for real 
| | > and
| | > | 	complex arguments as R-devel (as of today) dislikes use of non-API
| | > | 	functions Rf_EncodeComplex?, ?Rf_EncodeReal?, ?Rf_formatComplex?
| | > |
| | > | So maybe Dirk has a plan to fix it.
| | >
| | > I do not.
| | 
| | Fine. So I'll fix it.
| 
| Hold on. 
| 
| I am in the middle of it. I do have a poor replacementment for EncodeReal,
| and am about to test one for complex. Will post soon.
| 
| Am not covering scientific notation at this point.

Ok, here replacement candidates.  Kudos to Kevin for sending something
reproducible that triggered this.  This snipped below grew from his code and
provids replacement candidates for coerce_to_string() for the real and
complex cases, not using the internal R functions (which I also did not look
at).  Obviously the function headers need to change from the sample to what
api.cpp uses.

What we get is simple snprintf() calls which almost surely is less featureful
than what R has, but please complaon to R Core about the sillyness of us not
being able to use _existing and tested functions_.  It's painful.


Dirk

#include <Rcpp.h>

static const char* dropTrailing0(char *s, char cdec) {
    /* Note that  's'  is modified */
    char *p = s;
    for (p = s; *p; p++) {
      if(*p == cdec) {
        char *replace = p++;
	      while ('0' <= *p  &&  *p <= '9')
		      if(*(p++) != '0')
		        replace = p;
	        if(replace != p)
		        while((*(replace++) = *(p++)))
		           ;
	        break;  
	   }
    }
    return s;
}

//template <> 
// const char* coerce_to_string/*<REALSXP>*/(double x){
// [[Rcpp::export]]
const char* coerce_to_stringRE(double x){
    int w,d,e ;
    // cf src/main/format.c in R's sources:
    //   The return values are
    //     w : the required field width
    //     d : use %w.df in fixed format, %#w.de in scientific format
    //     e : use scientific format if != 0, value is number of exp digits - 1
    //
    //   nsmall specifies the minimum number of decimal digits in fixed format:
    //   it is 0 except when called from do_format.
    Rf_formatReal( &x, 1, &w, &d, &e, 0 ) ;
    // we are no longer allowed to use this:
    //     char* tmp = const_cast<char*>( Rf_EncodeReal(x, w, d, e, '.') );
    // so approximate it poorly as
    char tmp[128];
    snprintf(tmp, 127, "%*.*f", w, d, x);
    //Rcpp::Rcout << "Vec is " << vec << std::endl;
    return dropTrailing0(tmp, '.');
     
}

//template <> 
//const char* coerce_to_string/*<CPLXSXP>*/(Rcomplex x){
// [[Rcpp::export]]
std::string coerce_to_stringCP(Rcomplex x){
    int wr, dr, er, wi, di, ei;
    // cf src/main/format.c in R's sources:
    Rf_formatComplex(&x, 1, &wr, &dr, &er, &wi, &di, &ei, 0);
    //return Rf_EncodeComplex(x, wr, dr, er, wi, di, ei, '.' );

    // we are no longer allowed to use this:
    //     Rf_EncodeComplex(x, wr, dr, er, wi, di, ei, '.' );
    // so approximate it poorly as
    char tmp[128];
    snprintf(tmp, 127, "%*.*f+%*.*fi", wr, dr, x.r, wi, di, x.i);
    return std::string(tmp);  // force a copy
}

using namespace Rcpp;

// // [[Rcpp::export]]
// IntegerVector counts(NumericVector x) {
//  return table(x);
// }
#
Cool. I'll have a look when I'm back from easter weekend.

Romain

Le 2013-03-29 16:00, Dirk Eddelbuettel a ?crit?:
#
On 29 March 2013 at 16:20, romain at r-enthusiasts.com wrote:
| Cool. I'll have a look when I'm back from easter weekend.

Sounds good.

And that point, it would be really nice if you could also restore the ability
to build Rcpp, which appears to have broken with your Data.Frame patch.

Details are below.

Dirk

edd at max:~/svn/rcpp/pkg$ R CMD build Rcpp
* checking for file ?Rcpp/DESCRIPTION? ... OK
* preparing ?Rcpp?:
* checking DESCRIPTION meta-information ... OK
* cleaning src
* running ?cleanup?
* installing the package to process help pages
      -----------------------------------
* installing *source* package ?Rcpp? ...
** libs
ccache g++-4.7 -I/usr/share/R/include -DNDEBUG -I../inst/include/     -fpic  -g0 -O3 -Wall -pipe -Wno-variadic-macros -pedantic -c Date.cpp -o Date.o
ccache g++-4.7 -I/usr/share/R/include -DNDEBUG -I../inst/include/     -fpic  -g0 -O3 -Wall -pipe -Wno-variadic-macros -pedantic -c Module.cpp -o Module.o
In file included from ../inst/include/RcppCommon.h:102:0,
                 from ../inst/include/Rcpp.h:27,
                 from Module.cpp:22:
../inst/include/Rcpp/Named.h: In instantiation of ?Rcpp::traits::named_object<SEXPREC*> Rcpp::Argument::operator=(const T&) [with T = int]?:
Module.cpp:40:128:   required from here
../inst/include/Rcpp/Named.h:34:52: error: ?wrap? was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
In file included from ../inst/include/RcppCommon.h:117:0,
                 from ../inst/include/Rcpp.h:27,
                 from Module.cpp:22:
../inst/include/Rcpp/internal/wrap.h:902:13: note: ?template<class InputIterator> SEXPREC* Rcpp::wrap(InputIterator, InputIterator)? declared here, later in the translation unit
In file included from ../inst/include/RcppCommon.h:102:0,
                 from ../inst/include/Rcpp.h:27,
                 from Module.cpp:22:
../inst/include/Rcpp/Named.h: In instantiation of ?Rcpp::traits::named_object<SEXPREC*> Rcpp::Argument::operator=(const T&) [with T = char [5]]?:
Module.cpp:40:146:   required from here
../inst/include/Rcpp/Named.h:34:52: error: ?wrap? was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
In file included from ../inst/include/RcppCommon.h:117:0,
                 from ../inst/include/Rcpp.h:27,
                 from Module.cpp:22:
../inst/include/Rcpp/internal/wrap.h:902:13: note: ?template<class InputIterator> SEXPREC* Rcpp::wrap(InputIterator, InputIterator)? declared here, later in the translation unit
In file included from ../inst/include/RcppCommon.h:102:0,
                 from ../inst/include/Rcpp.h:27,
                 from Module.cpp:22:
../inst/include/Rcpp/Named.h: In instantiation of ?Rcpp::traits::named_object<SEXPREC*> Rcpp::Argument::operator=(const T&) [with T = char [12]]?:
Module.cpp:52:127:   required from here
../inst/include/Rcpp/Named.h:34:52: error: ?wrap? was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
In file included from ../inst/include/RcppCommon.h:117:0,
                 from ../inst/include/Rcpp.h:27,
                 from Module.cpp:22:
../inst/include/Rcpp/internal/wrap.h:902:13: note: ?template<class InputIterator> SEXPREC* Rcpp::wrap(InputIterator, InputIterator)? declared here, later in the translation unit
In file included from ../inst/include/RcppCommon.h:102:0,
                 from ../inst/include/Rcpp.h:27,
                 from Module.cpp:22:
../inst/include/Rcpp/Named.h: In instantiation of ?Rcpp::traits::named_object<SEXPREC*> Rcpp::Argument::operator=(const T&) [with T = char [15]]?:
Module.cpp:61:133:   required from here
../inst/include/Rcpp/Named.h:34:52: error: ?wrap? was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
In file included from ../inst/include/RcppCommon.h:117:0,
                 from ../inst/include/Rcpp.h:27,
                 from Module.cpp:22:
../inst/include/Rcpp/internal/wrap.h:902:13: note: ?template<class InputIterator> SEXPREC* Rcpp::wrap(InputIterator, InputIterator)? declared here, later in the translation unit
In file included from ../inst/include/RcppCommon.h:102:0,
                 from ../inst/include/Rcpp.h:27,
                 from Module.cpp:22:
../inst/include/Rcpp/Named.h: In instantiation of ?Rcpp::traits::named_object<SEXPREC*> Rcpp::Argument::operator=(const T&) [with T = char [22]]?:
Module.cpp:67:133:   required from here
../inst/include/Rcpp/Named.h:34:52: error: ?wrap? was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
In file included from ../inst/include/RcppCommon.h:117:0,
                 from ../inst/include/Rcpp.h:27,
                 from Module.cpp:22:
../inst/include/Rcpp/internal/wrap.h:902:13: note: ?template<class InputIterator> SEXPREC* Rcpp::wrap(InputIterator, InputIterator)? declared here, later in the translation unit
In file included from ../inst/include/RcppCommon.h:102:0,
                 from ../inst/include/Rcpp.h:27,
                 from Module.cpp:22:
../inst/include/Rcpp/Named.h: In instantiation of ?Rcpp::traits::named_object<SEXPREC*> Rcpp::Argument::operator=(const T&) [with T = char [11]]?:
Module.cpp:73:142:   required from here
../inst/include/Rcpp/Named.h:34:52: error: ?wrap? was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
In file included from ../inst/include/RcppCommon.h:117:0,
                 from ../inst/include/Rcpp.h:27,
                 from Module.cpp:22:
../inst/include/Rcpp/internal/wrap.h:902:13: note: ?template<class InputIterator> SEXPREC* Rcpp::wrap(InputIterator, InputIterator)? declared here, later in the translation unit
In file included from ../inst/include/RcppCommon.h:102:0,
                 from ../inst/include/Rcpp.h:27,
                 from Module.cpp:22:
../inst/include/Rcpp/Named.h: In instantiation of ?Rcpp::traits::named_object<SEXPREC*> Rcpp::Argument::operator=(const T&) [with T = char [20]]?:
Module.cpp:77:139:   required from here
../inst/include/Rcpp/Named.h:34:52: error: ?wrap? was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
In file included from ../inst/include/RcppCommon.h:117:0,
                 from ../inst/include/Rcpp.h:27,
                 from Module.cpp:22:
../inst/include/Rcpp/internal/wrap.h:902:13: note: ?template<class InputIterator> SEXPREC* Rcpp::wrap(InputIterator, InputIterator)? declared here, later in the translation unit
In file included from ../inst/include/RcppCommon.h:102:0,
                 from ../inst/include/Rcpp.h:27,
                 from Module.cpp:22:
../inst/include/Rcpp/Named.h: In instantiation of ?Rcpp::traits::named_object<SEXPREC*> Rcpp::Argument::operator=(const T&) [with T = SEXPREC*]?:
Module.cpp:265:50:   required from here
../inst/include/Rcpp/Named.h:34:52: error: ?wrap? was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
In file included from ../inst/include/RcppCommon.h:117:0,
                 from ../inst/include/Rcpp.h:27,
                 from Module.cpp:22:
../inst/include/Rcpp/internal/wrap.h:902:13: note: ?template<class InputIterator> SEXPREC* Rcpp::wrap(InputIterator, InputIterator)? declared here, later in the translation unit
In file included from ../inst/include/RcppCommon.h:102:0,
                 from ../inst/include/Rcpp.h:27,
                 from Module.cpp:22:
../inst/include/Rcpp/Named.h: In instantiation of ?Rcpp::traits::named_object<SEXPREC*> Rcpp::Argument::operator=(const T&) [with T = bool]?:
Module.cpp:266:39:   required from here
../inst/include/Rcpp/Named.h:34:52: error: ?wrap? was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
In file included from ../inst/include/RcppCommon.h:117:0,
                 from ../inst/include/Rcpp.h:27,
                 from Module.cpp:22:
../inst/include/Rcpp/internal/wrap.h:902:13: note: ?template<class InputIterator> SEXPREC* Rcpp::wrap(InputIterator, InputIterator)? declared here, later in the translation unit
make: *** [Module.o] Error 1
ERROR: compilation failed for package ?Rcpp?
* removing ?/tmp/RtmpfejSO9/Rinst312b332a9a19/Rcpp?
      -----------------------------------
ERROR: package installation failed
edd at max:~/svn/rcpp/pkg$ 
| 
| Romain
| 
| Le 2013-03-29 16:00, Dirk Eddelbuettel a ?crit?:
| > On 29 March 2013 at 09:40, Dirk Eddelbuettel wrote:
| > |
| > | On 29 March 2013 at 15:24, romain at r-enthusiasts.com wrote:
| > | | Le 2013-03-29 14:31, Dirk Eddelbuettel a ?crit?:
| > | | > On 29 March 2013 at 09:11, romain at r-enthusiasts.com wrote:
| > | | > |
| > | | > | Hello,
| > | | > |
| > | | > | This is related to this change:
| > | | > |
| > | | > | 2013-01-15  Dirk Eddelbuettel  <edd at debian.org>
| > | | > |
| > | | > | 	* src/api.cpp (Rcpp): Commented-out coerce_to_string() for 
| > real
| > | | > and
| > | | > | 	complex arguments as R-devel (as of today) dislikes use of 
| > non-API
| > | | > | 	functions Rf_EncodeComplex?, ?Rf_EncodeReal?, 
| > ?Rf_formatComplex?
| > | | > |
| > | | > | So maybe Dirk has a plan to fix it.
| > | | >
| > | | > I do not.
| > | |
| > | | Fine. So I'll fix it.
| > |
| > | Hold on.
| > |
| > | I am in the middle of it. I do have a poor replacementment for 
| > EncodeReal,
| > | and am about to test one for complex. Will post soon.
| > |
| > | Am not covering scientific notation at this point.
| >
| > Ok, here replacement candidates.  Kudos to Kevin for sending 
| > something
| > reproducible that triggered this.  This snipped below grew from his 
| > code and
| > provids replacement candidates for coerce_to_string() for the real 
| > and
| > complex cases, not using the internal R functions (which I also did 
| > not look
| > at).  Obviously the function headers need to change from the sample 
| > to what
| > api.cpp uses.
| >
| > What we get is simple snprintf() calls which almost surely is less 
| > featureful
| > than what R has, but please complaon to R Core about the sillyness of 
| > us not
| > being able to use _existing and tested functions_.  It's painful.
| >
| >
| > Dirk
| >
| > #include <Rcpp.h>
| >
| > static const char* dropTrailing0(char *s, char cdec) {
| >     /* Note that  's'  is modified */
| >     char *p = s;
| >     for (p = s; *p; p++) {
| >       if(*p == cdec) {
| >         char *replace = p++;
| > 	      while ('0' <= *p  &&  *p <= '9')
| > 		      if(*(p++) != '0')
| > 		        replace = p;
| > 	        if(replace != p)
| > 		        while((*(replace++) = *(p++)))
| > 		           ;
| > 	        break;
| > 	   }
| >     }
| >     return s;
| > }
| >
| > //template <>
| > // const char* coerce_to_string/*<REALSXP>*/(double x){
| > // [[Rcpp::export]]
| > const char* coerce_to_stringRE(double x){
| >     int w,d,e ;
| >     // cf src/main/format.c in R's sources:
| >     //   The return values are
| >     //     w : the required field width
| >     //     d : use %w.df in fixed format, %#w.de in scientific format
| >     //     e : use scientific format if != 0, value is number of exp
| > digits - 1
| >     //
| >     //   nsmall specifies the minimum number of decimal digits in
| > fixed format:
| >     //   it is 0 except when called from do_format.
| >     Rf_formatReal( &x, 1, &w, &d, &e, 0 ) ;
| >     // we are no longer allowed to use this:
| >     //     char* tmp = const_cast<char*>( Rf_EncodeReal(x, w, d, e, 
| > '.') );
| >     // so approximate it poorly as
| >     char tmp[128];
| >     snprintf(tmp, 127, "%*.*f", w, d, x);
| >     //Rcpp::Rcout << "Vec is " << vec << std::endl;
| >     return dropTrailing0(tmp, '.');
| >
| > }
| >
| > //template <>
| > //const char* coerce_to_string/*<CPLXSXP>*/(Rcomplex x){
| > // [[Rcpp::export]]
| > std::string coerce_to_stringCP(Rcomplex x){
| >     int wr, dr, er, wi, di, ei;
| >     // cf src/main/format.c in R's sources:
| >     Rf_formatComplex(&x, 1, &wr, &dr, &er, &wi, &di, &ei, 0);
| >     //return Rf_EncodeComplex(x, wr, dr, er, wi, di, ei, '.' );
| >
| >     // we are no longer allowed to use this:
| >     //     Rf_EncodeComplex(x, wr, dr, er, wi, di, ei, '.' );
| >     // so approximate it poorly as
| >     char tmp[128];
| >     snprintf(tmp, 127, "%*.*f+%*.*fi", wr, dr, x.r, wi, di, x.i);
| >     return std::string(tmp);  // force a copy
| > }
| >
| > using namespace Rcpp;
| >
| > // // [[Rcpp::export]]
| > // IntegerVector counts(NumericVector x) {
| > //  return table(x);
| > // }
|
#
Thanks for the quick responses. It seems counter-productive for R Core to
be removing API entry points, at least doing so without informing package
maintainers of newly implemented and tested alternatives. I wonder if it's
due to the introduction of 'long' vectors, and the team decided it would be
easier to just remove the API entry points, rather than adapting them? Just
conjecture, though.

Thanks for the help.
-Kevin
On Fri, Mar 29, 2013 at 8:20 AM, <romain at r-enthusiasts.com> wrote:

            
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130329/409ebcef/attachment-0001.html>
#
On 29 March 2013 at 08:48, Kevin Ushey wrote:
| Thanks for the quick responses. 

Thanks for the reproducible bug report.  

In (some version of) Rcpp 0.10.3.1 [1] you can now use your function again:

R> sourceCpp("/tmp/kevin.cpp")
R> set.seed(42)
R> x <- sample(1:10, 20, replace=TRUE)
R> table(x)
x
 2  3  5  6  7  8  9 10 
 2  2  3  2  2  3  1  5 
R> counts(x)
 2  3  5  6  7  8  9 10 
 2  2  3  2  2  3  1  5 
R> 


| It seems counter-productive for R Core to be
| removing API entry points, at least doing so without informing package

Not quite as we were using a non-exported function.  The counter-productive
nature of this is solely on "their" decision of what is, and what is not,
part of the API.  If we use something we are not supposed to use, we get to
pay the price of it being pulled.

"They" are pretty good about maintaining what is the declared API.

| maintainers of newly implemented and tested alternatives. I wonder if it's due
| to the introduction of 'long' vectors, and the team decided it would be easier
| to just remove the API entry points, rather than adapting them? Just
| conjecture, though.

No relationship.

Dirk

[1] In attempting to address the long-standding (and very annoying) but with
Date.Frame, Romain inadvertently broke SVN trunk. And I am not managing to
get it back right now.  But if you apply my revision 4297 to, say, the 0.10.3
release (and hence ignore the Data.Frame change) then the resulting 0.10.3.1
build, tests, and gets your counts() function back.  

| 
| Thanks for the help.
| -Kevin
|
| On Fri, Mar 29, 2013 at 8:20 AM, <romain at r-enthusiasts.com> wrote:
| 
|     Cool. I'll have a look when I'm back from easter weekend.
| 
|     Romain
| 
|     Le 2013-03-29 16:00, Dirk Eddelbuettel a ?crit?:
| 
|
| On 29 March 2013 at 09:40, Dirk Eddelbuettel wrote:
|         |
| | On 29 March 2013 at 15:24, romain at r-enthusiasts.com wrote:
|         | | Le 2013-03-29 14:31, Dirk Eddelbuettel a ?crit?:
| | | > On 29 March 2013 at 09:11, romain at r-enthusiasts.com wrote:
|         | | > |
|         | | > | Hello,
|         | | > |
|         | | > | This is related to this change:
|         | | > |
|         | | > | 2013-01-15 ?Dirk Eddelbuettel ?<edd at debian.org>
|         | | > |
|         | | > | ? ? ? ? * src/api.cpp (Rcpp): Commented-out
|         coerce_to_string() for real
|         | | > and
|         | | > | ? ? ? ? complex arguments as R-devel (as of today) dislikes
|         use of non-API
|         | | > | ? ? ? ? functions Rf_EncodeComplex?, ?Rf_EncodeReal?,
|         ?Rf_formatComplex?
|         | | > |
|         | | > | So maybe Dirk has a plan to fix it.
|         | | >
|         | | > I do not.
|         | |
|         | | Fine. So I'll fix it.
|         |
|         | Hold on.
|         |
|         | I am in the middle of it. I do have a poor replacementment for
|         EncodeReal,
|         | and am about to test one for complex. Will post soon.
|         |
|         | Am not covering scientific notation at this point.
| 
|         Ok, here replacement candidates. ?Kudos to Kevin for sending something
|         reproducible that triggered this. ?This snipped below grew from his
|         code and
|         provids replacement candidates for coerce_to_string() for the real and
|         complex cases, not using the internal R functions (which I also did not
|         look
|         at). ?Obviously the function headers need to change from the sample to
|         what
|         api.cpp uses.
| 
|         What we get is simple snprintf() calls which almost surely is less
|         featureful
|         than what R has, but please complaon to R Core about the sillyness of
|         us not
|         being able to use _existing and tested functions_. ?It's painful.
| 
| 
|         Dirk
| 
|         #include <Rcpp.h>
| 
|         static const char* dropTrailing0(char *s, char cdec) {
|         ? ? /* Note that ?'s' ?is modified */
|         ? ? char *p = s;
|         ? ? for (p = s; *p; p++) {
|         ? ? ? if(*p == cdec) {
|         ? ? ? ? char *replace = p++;
|         ? ? ? ? ? ? ? while ('0' <= *p ?&& ?*p <= '9')
|         ? ? ? ? ? ? ? ? ? ? ? if(*(p++) != '0')
|         ? ? ? ? ? ? ? ? ? ? ? ? replace = p;
|         ? ? ? ? ? ? ? ? if(replace != p)
|         ? ? ? ? ? ? ? ? ? ? ? ? while((*(replace++) = *(p++)))
|         ? ? ? ? ? ? ? ? ? ? ? ? ? ?;
|         ? ? ? ? ? ? ? ? break;
|         ? ? ? ? ? ?}
|         ? ? }
|         ? ? return s;
|         }
| 
|         //template <>
|         // const char* coerce_to_string/*<REALSXP>*/(double x){
|         // [[Rcpp::export]]
|         const char* coerce_to_stringRE(double x){
|         ? ? int w,d,e ;
|         ? ? // cf src/main/format.c in R's sources:
|         ? ? // ? The return values are
|         ? ? // ? ? w : the required field width
|         ? ? // ? ? d : use %w.df in fixed format, %#w.de in scientific
|         format
|         ? ? // ? ? e : use scientific format if != 0, value is number of
|         exp
|         digits - 1
|         ? ? //
|         ? ? // ? nsmall specifies the minimum number of decimal digits in
|         fixed format:
|         ? ? // ? it is 0 except when called from do_format.
|         ? ? Rf_formatReal( &x, 1, &w, &d, &e, 0 ) ;
|         ? ? // we are no longer allowed to use this:
|         ? ? // ? ? char* tmp = const_cast<char*>( Rf_EncodeReal(x, w, d, e,
|         '.') );
|         ? ? // so approximate it poorly as
|         ? ? char tmp[128];
|         ? ? snprintf(tmp, 127, "%*.*f", w, d, x);
|         ? ? //Rcpp::Rcout << "Vec is " << vec << std::endl;
|         ? ? return dropTrailing0(tmp, '.');
| 
|         }
| 
|         //template <>
|         //const char* coerce_to_string/*<CPLXSXP>*/(Rcomplex x){
|         // [[Rcpp::export]]
|         std::string coerce_to_stringCP(Rcomplex x){
|         ? ? int wr, dr, er, wi, di, ei;
|         ? ? // cf src/main/format.c in R's sources:
|         ? ? Rf_formatComplex(&x, 1, &wr, &dr, &er, &wi, &di, &ei, 0);
|         ? ? //return Rf_EncodeComplex(x, wr, dr, er, wi, di, ei, '.' );
| 
|         ? ? // we are no longer allowed to use this:
|         ? ? // ? ? Rf_EncodeComplex(x, wr, dr, er, wi, di, ei, '.' );
|         ? ? // so approximate it poorly as
|         ? ? char tmp[128];
|         ? ? snprintf(tmp, 127, "%*.*f+%*.*fi", wr, dr, x.r, wi, di, x.i);
|         ? ? return std::string(tmp); ?// force a copy
|         }
| 
|         using namespace Rcpp;
| 
|         // // [[Rcpp::export]]
|         // IntegerVector counts(NumericVector x) {
|         // ?return table(x);
|         // }
| 
| 
|     _______________________________________________
|     Rcpp-devel mailing list
|     Rcpp-devel at lists.r-forge.r-project.org
|     https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
| 
|
#
Great. Thanks for the quick response and all the work you and Romain put
into Rcpp!

-Kevin
On Fri, Mar 29, 2013 at 9:35 AM, Dirk Eddelbuettel <edd at debian.org> wrote:

            
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130329/e74dfc7b/attachment-0001.html>