Your function looks fine. Just remember the degrees of freedom here is in fact $min(\text{Cols}-1, \text{ Rows}-1)$, so your df will be $2 - 1 = 1$. Both the "lsr" and "rcompanion" packages also have functions to calculate Cramer's V. The latter is particularly nice as it gives bootstrap estimated confidence intervals for the V statistic.
Reproducible example:
# Agresti(2007) p.39 - Taken from ?chisq.text documentation
M <- as.table(rbind(c(762, 327, 468), c(484, 239, 477)))
dimnames(M) <- list(gender = c("F", "M"), party = c("Democrat","Independent", "Republican"))
# Calculate the chi-square
Xsq <- chisq.test(M)
# Custom function
Cramers_V <- function(chi, n, df) sqrt((chi)/(n * df))
# Find degrees of freedom - min row or col - 1
df <- min(dim(M)) - 1
# Calculate
Cramers_V(chi = Xsq$statistic, n = sum(M), df = df)
# Result = 0.1044358
# Agrees with both:
# lsr::cramersV(M)
# rcompanion::cramerV(M, ci = TRUE)
There doesn't appear to be any definitive answer as to whether Cohen's W or Cramer's V is preferable. Both reduce to a $\phi$ correlation coefficient in the case of a 2x2 table.
V is more familiar to researchers and bounded by 0 and 1 which is nice. On the other hand, the magnitude or 'strength' of V depends on the degrees of freedom, so a V = .3 when df = 1 is not the same as V = .3 when df = 4. W doesn't appear to have this problem, and can be used to determine power for further studies following Cohen (1988), but it is not bounded by 1 (although it's rare W exceeds 1).
References
Cohen, J. (1988). Statistical power analysis for the behavioral sciences. Routledge.
Best Answer
I prefer the phi coefficient. It is also generalized for r x s table not only 2 x 2. Run the chi square test of independence and write down the value of the test statistics $\chi^2$. Then
$$ \phi = \sqrt{\frac{\chi^2}{n}} $$
where $n$ is your sample size. It is interpreted in the similar fashion as Pearson correlation coefficient.