In the $2\times 2$ case the distributional assumption is given by two independent binomial random variables $X_1 \sim Bin(n_1, \theta_1)$ and $X_2 \sim Bin(n_2, \theta_2)$. The null hypothesis is the equality $\theta_1=\theta_2$.
But Fisher's exact test is a conditional test: it relies on the conditional distribution of $X_1$ given $X_1+X_2$. This distribution is a hypergeometric distribution with one unknown parameter: the odds ratio $\psi=\frac{\frac{\theta_1}{1-\theta_1}}{\frac{\theta_2}{1-\theta_2}}$, and then the null hypothesis is $\psi=1$.
This distribution has its Wikipedia page.
To evaluate it with R, you can simply use the formula defining the conditional probability:
p1 <- 7/27
p2 <- 14/70
x1 <- 7; n1 <- 27
x2 <- 14; n2 <- 56
#
m <- x1+x2
dbinom(x1, n1, p1)*dbinom(x2, n2, p2)/sum(dbinom(0:m, n1, p1)*dbinom(m-(0:m), n2, p2))
[1] 0.1818838
Or use the dnoncenhypergeom
function of the MCMCpack
package:
psi <- p1/(1-p1)/(p2/(1-p2)) # this is the odds ratio
MCMCpack::dnoncenhypergeom(x=x1, n1, n2, x1+x2, psi)
[1] 0.1818838