Power for equal samples t test in R

For a two-tailed test with type I error, alpha, with samples each of size, n, with means and standard deviations we compute the power.

[COPY AND PASTE THE BELOW INTO R]

fn <- function (alpha,mean1,mean2,sd1,sd2,n) {
mdiff <- mean1 - mean2
pow <- 1 - pt(abs(qt(alpha/2, 2*n-2)), 2*n-2,
mdiff/sqrt((sd1*sd1)/n+(sd2*sd2)/n))
cat("Power for (two-tailed) unequal sized groups unpaired t-test =")
print(pow)
 }

[TYPE INTO R THE DESIRED INPUTS].

alpha <- 0.05
mean1 <- 2
mean2 <- 0
sd1 <- 4
sd2 <- 5
n <- 45

AND RUN

fn(alpha,mean1,mean2,sd1,sd2,n)