Skip to content

rrace() and rrank_single() are the same #250

@RobinHankin

Description

@RobinHankin

Well almost the same. rrace() is higher-level, dealing with named vectors, while rrank_single() is lower-level, dealing with numeric vectors.

Function rrace() is documented at man/rrace.Rd; and function rrank_single() is documented (alongside other functions such as rorder_single() at man/rrank.Rd.

The best solution, I think, is to delete rrace.Rd and add its content to rrank.Rd. And of course rationalise the code, which currently reads

`rrank_single` <- function(p){
    ell <- length(p)
    r <- integer(ell)
    i <- 1   # 'i' means placing.
    while(any(p > 0)){  
        m <- sample(ell,1,prob=p) #randomly chosen competitor
        r[i] <- m   # place 'i' is competitor 'm'  
        p[m] <- 0   # competitor 'm' can't place again.
        i <- i+1    # consider the next place
    }
    return(r)
}

[snip]

`rrace` <- function(strengths){
    out <- strengths
    for (i in seq_along(out)) {
        nextfinisher <- sample(names(strengths),size=1,prob=strengths)
        out[i] <- nextfinisher
        strengths <- strengths[names(strengths) != nextfinisher]
    }
    names(out) <- NULL
    return(out)
}

Looking at the above, it is not clear which is better, or faster. they use very different methods. But either way, this is not following the DRY rule unless

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions