Skip to content

where is internal function of sample()?

4 messages · Weijie Cai, Marc Schwartz, Brian Ripley +1 more

#
Hi there,

I am trying to write a c++ shared library for R. I need a function which has 
the same functionality as sample() in R, i.e., does permutation, sample 
with/without replacement. Does R have internal sample routine so that I can 
call it directly?

I did not find it in R.h, Rinternal.h.

Thanks
#
On Mon, 2005-04-11 at 23:04 -0400, Weijie Cai wrote:
A quick grep of the source code tree tells you that the function is
in .../src/main/random.c

A general pattern for C .Internal functions is to use a prefix of "do_"
in conjunction with the R function name. So in this case, the C function
is called do_sample and begins at line 391 (for 2.0.1 patched) in the
aforementioned C source file.

HTH,

Marc Schwartz
#
On Mon, 11 Apr 2005, Weijie Cai wrote:

            
That's because it is not in the API. The function is do_sample in 
src/main/random.c.  You could construct an appropriate call with some 
ingenuity.

Please note that R-devel is the list for C-level programming questions, as 
the posting guide points out.
#
On Mon, 11 Apr 2005, Marc Schwartz wrote:
and in the case of the few exceptions to this rule you can look in names.c 
for a complete table.

 	-thomas