All of these tries leave to the same result: 1) First I defined kmeansnew with the content of kmeans, but leaving the <environment: namespace:stats> out. Then I run environment(kmeansnew)<- environment(stats::kmeans) at the command line. 2) kmeansnew <- kmeans() {.... environment(kmeansnew)<- environment(stats::kmeans) } 3) kmeansnew <- kmeans() {....} environment(kmeansnew)<- environment(stats::kmeans)
When I do kmeansnew(iris[-5],4) it returns: Error in do_one(nmeth) : object 'R_kmns' not found 'R_kmns' is a .FORTRAN that is called by the original kmeans(). it is the same error as if i would just leave <environment: namespace:stats> out. On Sat, Jan 14, 2012 at 11:50 AM, Duncan Murdoch <murdoch.dun...@gmail.com> wrote: > On 12-01-14 3:58 AM, Rui Esteves wrote: >> >> Thank you both. >> >> 1) As Duncan said, if I leave<environment: namespace:stats> out, it >> will not work since it is using .C and .Fortran functions that kmeans >> calls. >> I >> 2) don`t know how to use the as.environment() (I did not understood by >> reading the help). >> >> 3) Setting environment(kmeansnew)<- environment(stats::kmeans) does >> not work as well. > > > I think you need to explain what "does not work" means. What did you do, > and how do you know it didn't work? > >> >> 4) Using fix() works, but then I don`t know how to store just the >> function in an external file. To use it in another computer, for >> example. If I use save(myfunc,"myFile.R", ASCII=TRUE) it doesn't work >> when I try to load it again using myfunc=load("myFile.R") > > > Don't use load() on a source file. Use load() on a binary file produced by > save(). You could save() your working function, but then you can't edit it > outside of R. To produce a .R file that you can use in another session, > you're going to need to produce the function, then modify the environment, > using 2 or 3 above. > > Duncan Murdoch ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.