C_kmns object could not be found when passing to .Fortran ()

I am trying to change a function stats::kmeansto return the number of iterations ( see here ). When I copy the source to my own file, modify the function and run it, I get an error message about the object C_kmnswhen I try to execute the function do_one. This object is passed to the call .Fortranand is not created anywhere in the function kmeans. Where does this object come from?

The error I get is

Error in do_one(nmeth) : object 'C_kmns' not found

Here is a snippet of an “abusive” call.

   do_one <- function(nmeth) {
      Z <-
               switch(nmeth,
                        { # 1
                           Z <- .Fortran(C_kmns, as.double(x), as.integer(m),
                                    as.integer(ncol(x)),
                                    ...
+5
source share
1 answer

C_kmns is an unexported object in the statistics namespace. You can solve the problem by telling R where to find it with statistics: C_kmns. in your example:

Z <- .Fortran(stats:::C_kmns, as.double(x), as.integer(m),
                                    as.integer(ncol(x)),
                                    ...

, , , getAnywhere("C_kmns")

+8

All Articles