Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8632373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:20:36+00:00 2026-06-12T09:20:36+00:00

The ‘sparcl’ package uses the ‘kmeans’ function in the standard ‘stat’ package. I want

  • 0

The ‘sparcl’ package uses the ‘kmeans’ function in the standard ‘stat’ package. I want to make it use my own implementation of kmeans++ instead.

One way to do this would be to edit the code in the sparcl package itself. I’d prefer to avoid this, both because it would be messy and because I’m not sure how I would then install that edited code in R.

Unfortunately, the superassignment operator “<<-” doesn’t work:

> kmeans <<- function(x) print("hi!")
Error: cannot change value of locked binding for 'kmeans'

neither does “assign”:

assign("kmeans",function(x) {print("HI THERE!"); return(FALSE)},pos="package:sparcl")
Error in assign("is.null", function(x) { : 
  cannot add bindings to a locked environment

So is editing the package code the only way?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:20:37+00:00Added an answer on June 12, 2026 at 9:20 am

    On further thought (and after re-reading your question), here’s a simple solution that should work for you.

    All you need to do is to assign your edited version of kmeans() to the symbol kmeans in the global environment. In other words, at the command line do this:

    kmeans <- function(...) plot(rnorm(99), col="red") # but using your own edits
    
    ## Then run an example from ?KMeansSparseCluster to see that it works.
    library(sparcl)
    x <- matrix(rnorm(50*300),ncol=300)
    x[1:25,1:50] <- x[1:25,1:50]+1
    x <- scale(x, TRUE, TRUE)
    KMeansSparseCluster.permute(x,K=2,wbounds=seq(3,9,len=15),nperms=5)
    

    This works because KMeansSparseCluster() (and calls to any other functions in package:sparcl) look for kmeans first in namespace:sparcl, then in imports:sparcl, then in namespace:base, and then in .GlobalEnv, where it’ll find your redefined kmeans before it gets to the one in package:stats. To have a look yourself, try this:

    parent.env(asNamespace("sparcl"))
    parent.env(parent.env(asNamespace("sparcl")))
    parent.env(parent.env(parent.env(asNamespace("sparcl"))))
    ## etc., also wrapping any of the environments above in calls to ls() 
    ## to see what's in 'em
    

    Nicely, functions from the stats package that use kmeans() won’t be disrupted by your version, because they will find kmeans in their own namespace, before the symbol-search ever gets to the global environment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a function that will clean a strings' special characters. I do NOT
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
I was writing code for dragging mechanism which invokes to wait for small period
I've got a string that has curly quotes in it. I'd like to replace
I downloaded PostgreSQL from the official website and ran the .dmg installer. After that
This is how I get the tags of a body of text. var tags
I'm running a Octopress blog which is based on Jekyll . Now I wanted
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.