Building R package: "Found" rand ", possibly from" rand "(C)" NOTE when checking the package

I am creating an R package that contains C ++ code. Among other things, I am using the rand () function. The package checks and builds without any disturbance on my Linux machine. However, when I try to inspect a Windows assembly using the Windows Designer , I get the following warning:

* checking compiled code ... NOTE
File 'tagcloud/libs/i386/tagcloud.dll':
  Found 'rand', possibly from 'rand' (C)
    Object: 'overlap.o'
  Found 'srand', possibly from 'srand' (C)
    Object: 'overlap.o'
File 'tagcloud/libs/x64/tagcloud.dll':
  Found 'rand', possibly from 'rand' (C)
    Object: 'overlap.o'
  Found 'srand', possibly from 'srand' (C)
    Object: 'overlap.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.

      

Here's some sample code:

#include "Rcpp.h"
#include <cstdlib>
#include <time.h>

using namespace Rcpp;

RcppExport SEXP test(  ) {
  double x ;
  srand( (unsigned) time(NULL) );
  x = rand();
  return( 1 );
}

      

I don't understand the complaint about rand (). I also don't see where in the code I am "calling entry points that can end R" or "writing to stdout / stderr", but then if I remove the rand / srand calls this message goes away.

Google shows many packages that seem to have the same NOTE in their logs. Did you see it? Is there a way to get rid of it?

+3


source to share


1 answer


The discussion in the comments already touches on an important point: R (as of the end) complains about the use of rand()

and srand()

. [Note that this is an R problem, not an Rcpp problem. ]

The thought that in some cases in the past rand()

was really bad on some systems. Therefore, warnings persist. See, for example, this page at cppreference.com :



There are no guarantees as to the quality of the generated random sequence. Previously, some implementations of rand () had serious flaws in the randomness, distribution, and period of the generated sequence (in one well-known example, the LSB was simply alternated between 1 and 0 between calls).

rand () is not recommended for serious random number generation needs such as cryptography. It is recommended to use the C ++ 11 random number generator to replace rand (). (Since C ++ 11)

In the case of the R and Rcpp package, you have no reason to rely on rand()

as R comes with several high quality generators. For details on how to access them from C code, and numerous Rcpp examples (here, Rcpp documtation, Rcpp Gallery), see the R Extensions Writing Guide. How to access them from C ++ via Rcpp.

+3


source







All Articles