Algorithm for `rmarkovchain` in R What method or algorithm is used in the function rmarkovchain from the R-package markovchain to generate samples and how does it work?
Edit:
I was interested in the following part from a mathematical standpoint: outstate <- sample(size = 1, x = markovchain@states, prob = rowProbs). What is the math/formula behind this statement? I'm sorry that this wasn't clear from my question.
 A: If you look at the function rmarkovchain, meaning you simply type rmarkovchain, you can spot the lines
for (i in 1:n) {
    sampledValues <- markovchainSequence(n = 1, markovchain = object[[1]], 
        ...)
    outIter <- rep(i, length(sampledValues))
    if (dim(object) > 1) {
        for (j in 2:dim(object)) {
          pos2take <- length(sampledValues)
          newVals <- markovchainSequence(n = 1, markovchain = object[[j]], 
            t0 = sampledValues[pos2take])
          outIter <- c(outIter, i)
          sampledValues <- c(sampledValues, newVals)
        }
    }
    iteration <- c(iteration, outIter)
    values <- c(values, sampledValues)
}

that are those where simulation takes place. They rely on markovchainSequence and if you type again markovchainSequence, you can see that the simulation part is
for (i in 1:n) {
    rowProbs <- markovchain@transitionMatrix[which(markovchain@states == 
        state), ]
    outstate <- sample(size = 1, x = markovchain@states, 
        prob = rowProbs)
    chain[i] <- outstate
    state <- outstate
}

which means there is nothing surprising in the way the Markov chain is simulated: given the current state (or state), take the row of the Markov transition matrix 
rowProbs <- markovchain@transitionMatrix[which(markovchain@states == 
            state), ]

and sample (or sample) one state according to the probability distribution on the states defined by that row
outstate <- sample(size = 1, x = markovchain@states, 
            prob = rowProbs)

A: Here is an expanded version of my comment.
R's internal sample() function is implemented as per https://svn.r-project.org/R/trunk/src/main/random.c.  There are two methods implemented.  The first is the "classic" inversion approach- sample $U\sim$Uniform$(0,1)$ and find $k$ such that $\sum_{j< k} p_j \leq U < \sum_{j\leq k} p_j$ (using hopefully obvious notation).
As Brian Ripley reported https://stat.ethz.ch/pipermail/r-devel/2005-August/034412.html, we looked at efficient algorithms for sample() in 2005.  It is difficult to come up with a good one-size-fits all rule but as mentioned a basic rule of thumb is to use Walker's algorithm if there are more than 200 probabilities >= 0.1/n. And this is what is in the source code (the ?sample documentation says 250 but that is incorrect).
So, for the Markov chain application you mentioned, inversion sampling would always be used, not Walker's method.
As you've probably realised this might not be great for Markov chain (and similar) simulations where you will often take small (n=1 for Markov Chains) samples from the same, or similar, distributions.  In particular, for some transition matrices, it might be much more efficient to compute the lookup table for Walker's algorithm at the beginning.  (It also depends on how many update steps you want to do in the Markov chain etc).
