Is k
here the same as theta
?
I think so yes.
What is the relation between theta and r and p?
The major difference is how the negative binomial is written. Here the negative binomial is written as a Poisson mixture of gammas. See, e.g. here
for the derivation if you are unfamiliar with this notion.
Then write the mean of the gamma as $\mu$ and the variance of the gamma $\mu^2/\theta$. Recall the gamma mixes the Poisson rate parameter so that to get the marginal mean and variance of the Negative binomial, you need to integration out the gamma variations. To do this you can use conditional expectations, e.g.
$\mathbb{E}(y_i) = \mathbb{E}(\mathbb{E}(y_i | \lambda))$
where the inner expection is the Poisson, e.g.
$\mathbb{E}(y_i) = \mathbb{E}(\lambda) = \mu$
now the variance:
$$\mathbb{V}ar(y_i) = \mathbb{V}ar(\mathbb{E}(y_i | \lambda)) + \mathbb{E}(\mathbb{V}ar(y_i | \lambda))$$
now putting in the gamma values for the inner expectations and variances you see:
$$\mathbb{V}ar(y_i) = \mathbb{V}ar(\lambda) + \mathbb{E}(\lambda)$$
and we may evaluate both the variance and the expectation on the right hand side as mean and variance of the gamma, to get:
$$\mathbb{V}ar(y_i) =\frac{\mu^2}{\theta} + \mu$$
this is the parameterization that these packages appear to be using.
If you want to map this parameterization to the more common negative binomial parameters, write:
$p = \frac{\mu}{\mu + \theta}$ and $r=\theta$.