Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unable to find C_kmns object when passed to .Fortran()

I'm trying to modify the stats::kmeans function to 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 about object C_kmns missing when trying to execute the do_one function. This object is passed to a .Fortran call and is not being created anywhere in the kmeans function. Where does this object come from?

The error I'm getting is

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

Here's a code snippet of the "offending" call.

   do_one <- function(nmeth) {
      Z <-
               switch(nmeth,
                        { # 1
                           Z <- .Fortran(C_kmns, as.double(x), as.integer(m),
                                    as.integer(ncol(x)),
                                    ...
like image 744
Roman Luštrik Avatar asked Apr 20 '12 21:04

Roman Luštrik


1 Answers

C_kmns is a non-exported object in the stats namespace. You can solve the issue by telling R where to find it with stats:::C_kmns. in your example:

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

In general, when you get an object not found error, you can go looking for it with getAnywhere("C_kmns")

like image 133
Ian Fellows Avatar answered Sep 22 '22 05:09

Ian Fellows