Can run this code in one R studio but cannot execute this code in another R studio of Same version number

rnorm <- function (n,mean,sd)
{ mean+sd*scale(rnorm(n)) }

ran_num <- rnorm(16000, 25 ,5)

Your function is doing a recursive call to itself. R allows this because recursion can be very helpful.

If you want to use the original rnorm inside you need to either use a different name for your function (recommended) or specify the package for the original:

rnorm <- function(n,mean,sd){
  mean + sd * scale(stats::rnorm(n))
}

In general, "masking" an existing function just causes headaches. It's only needed when the intent is to replace that function in existing code you can't easily update. For example, dplyr masks the base package's setdiff function so it also works for datasets.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.