From edd at debian.org  Wed Nov  5 13:43:37 2014
From: edd at debian.org (Dirk Eddelbuettel)
Date: Wed, 5 Nov 2014 06:43:37 -0600
Subject: [Rd] Linking to the BH package introduces CRAN warnings
In-Reply-To: <54596763.3020700@gmail.com>
References: <5458D68D.3070102@gmail.com>
	<21592.58816.359652.109459@max.nulle.part>
	<0CDE01C7-C290-4CB8-A1ED-B2A8816CBA49@r-enthusiasts.com>
	<CABdHhvEiGiXAYymj4Fw2BTMw7Jq+BHBu0q=CR6kCRXYFph2VKw@mail.gmail.com>
	<54595506.7000706@gmail.com>
	<21593.22718.944171.419082@max.nulle.part>
	<54596763.3020700@gmail.com>
Message-ID: <21594.7033.486398.753912@max.nulle.part>


On 5 November 2014 at 00:55, kaveh wrote:
| Dear all,
| 
| 
| the simple code in below, when send to the
| win-builder returns the following (and no other)
| warning:
| 
| 
| * checking compiled code ... WARNING
| File 'quicky/libs/i386/quicky.dll':
|    Found '_ZSt4cerr', possibly from 'std::cerr' (C++)
|      Object: 'quicky.o'
|    Found 'abort', possibly from 'abort' (C), 'runtime' (Fortran)
|      Object: 'quicky.o'
| File 'quicky/libs/x64/quicky.dll':
|    Found '_ZSt4cerr', possibly from 'std::cerr' (C++)
|      Object: 'quicky.o'
|    Found 'abort', possibly from 'abort' (C), 'runtime' (Fortran)
|      Object: 'quicky.o'
| 
| Compiled code should not call entry points which might terminate R nor
| write to stdout/stderr instead of to the console, nor the C RNG.
| 
| See 'Writing portable packages' in the 'Writing R Extensions' manual.
| 
| 
| Here is the source:
| 
| #include <algorithm>
| #include <cstdlib>
| #include <ctime>
| #include <functional>
| #include <fstream>
| #include <iostream>
| #include <math.h>
| #include <time.h>
| #include <stdio.h>
| #include <stdlib.h>
| #include <sstream>
| #include <vector>
| #include <random>
| 
| #include <boost/math/distributions/normal.hpp>
| #include <boost/math/distributions/chi_squared.hpp>
| 
| #include <Eigen/Dense>
| 
| using namespace std;
| using namespace Eigen;
| using Eigen::MatrixXd;
| using Eigen::VectorXd;
| using Eigen::VectorXi;
| using Eigen::RowVectorXd;
| 
| 
| using boost::math::chi_squared;
| using boost::math::quantile;
| using boost::math::complement;
| using boost::math::normal_distribution;
| using namespace boost::math::policies;
| 
| typedef policy<
|        promote_double<true>
|        > my_policy_norm;
| typedef policy<
|        promote_double<true>
|        > my_policy_chi2;
| 
| typedef boost::math::normal_distribution<double,my_policy_norm> my_norm;
| typedef boost::math::chi_squared_distribution<double,my_policy_chi2> 
| my_chi2;
| 
| 
| VectorXd GetQs(const VectorXd& x){
|      const int n=x.size();
|      double mytol=1e-8;
|      double the_max=x.maxCoeff();
|      double the_min=x.minCoeff();
|      double the_rag=(the_max-the_min);
|      if(the_rag<mytol)    return(x);
|      if(1.0-the_max<mytol)    return(x);
|      if(the_min<mytol)    return(x);
|      VectorXd y=x.array();
|      for(int i=0;i<n;i++) 
| y(i)=sqrt(quantile(complement(my_chi2(1.0),x(i))));
|      return(y);
| }
| extern "C"{
|      void quicky(int* rn,double* xi,double* yi){
|          const int n=*rn;
|          VectorXd x=Map<VectorXd>(xi,n);
|          Map<VectorXd>(yi,n)=GetQs(x);
|      }
| }
| 
| 
| So I guess, I should fill a bug report with the
| BH maintainer?

Err, why? BH does nothing wrong. 

You are NOT forced or required to use the Boost distributions header __as R
comes with the equivalent functionality__ via the Rmath.h header file from R.
Which has functionality that Rcpp provides to you in scalar and vector form.

And there are probably several dozen examples of using the R distribution
functions from Rcpp.

So this is _precisely_ what I suggested several mails ago: do your homework,
identify which header is causing it.  And the obvious next step is then to
not use the header.

Dirk
 

| Best regards,
| 
| 
| On 2014-11-04 23:52, Dirk Eddelbuettel wrote:
| > Gentlemen,
| >
| > On 4 November 2014 at 23:36, kaveh wrote:
| > | Dear Hadley,
| > |
| > | Thank you for this information, maybe the CRAN gods
| > | will look favourably on this case too,
| >
| > You seemed to have missed a point my earlier email tried to stress: Inclusion
| > of BH does not lead to the warning.
| >
| > All this depends on WHICH headers are included, and the OP will need to sort
| > this out by modifying his code.
| >
| > Dirk
| >   
| > | Best regards,
| > |
| > | On 2014-11-04 23:32, Hadley Wickham wrote:
| > | >>> | However, it seems some of the codes in the BH package
| > | >>> | might. At any rate, when I include some boost headers such as
| > | >>> | boost/math/distributions/ through BH, I get the following warnings
| > | >>> |   when  submitting to the win-builder page:
| > | >>> |
| > | >>> |
| > | >>> |    Found '_ZSt4cerr', possibly from 'std::cerr' (C++)
| > | >>> |
| > | >>> |    Found 'abort', possibly from 'abort' (C), 'runtime' (Fortran)
| > | >>> |
| > | >>> |    Found '_ZSt4cerr', possibly from 'std::cerr' (C++)
| > | >>> |
| > | >>> |    Found 'abort', possibly from 'abort' (C), 'runtime' (Fortran)
| > | >> You?re kind of out of luck. These functions are both:
| > | >>   - used by the boost headers
| > | >>   - forbidden by R, well at least forbidden by CRAN
| > | > Maaaaybe - I had this note in RSQLite, and CRAN seemed ok with my explanation:
| > | >
| > | > * checking compiled code ... NOTE
| > | >    File ?/Users/hadley/Documents/databases/RSQLite.Rcheck/RSQLite/libs/RSQLite.so?:
| > | >      Found ?___stderrp?, possibly from ?stderr? (C)
| > | >        Object: ?sqlite-all.o?
| > | >
| > | >    This is in C code from the embedded SQLite database.
| > | >
| > | >
| > | > Hadley
| > | >
| > |
| >
| 

-- 
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org



[Rd] Linking to the BH package introduces CRAN warnings
Dirk Eddelbuettel