Here I'm doing it the hard way, but if you go through it, it might be enlightening. The basic idea is I construct the covariance matrix $\Sigma$, then use the eigenvector decomposition to compute the matrix $\Sigma^{1/2}$. Then if $u = (u_1,u_2)$, we get the formula: $(X,Y) = u + \Sigma^{1/2}z$, where the $z$ are a pair of independent standard normal random variables.
For example:
s1 = 2
s2 = 4
u1 = 10
u2 = 12
r = 0.8
covar = r*s1*s2
Sigma = matrix(ncol=2,nrow=2,c(s1^2,covar,covar,s2^2))
temp = eigen(Sigma)
SqrtSigma = temp$vectors%*%diag(sqrt(temp$values))%*%t(temp$vectors)
XYvec = c(u1,u2) + SqrtSigma%*%rnorm(2)
XYvec
# [,1]
# [1,] 9.265028
# [2,] 11.230126
I'll check it with a simulation:
x = rep(NA,1000)
y = rep(NA,1000)
for(i in 1:1000){
XYvec = c(u1,u2) + SqrtSigma%*%rnorm(2)
x[i] = XYvec[1]
y[i] = XYvec[2]
}
var(x)
# [1] 4.060218
var(y)
# [1] 16.18099
cor(x,y)
# [1] 0.8002916
mean(x)
# [1] 9.935937
mean(y)
# [1] 11.94783
mvnormin MASS library or https://cran.r-project.org/web/packages/mvtnorm/index.html , however as strictly software-related this kind of questions are off-topic on this site. – Tim Nov 10 '15 at 07:21