[R] Question about expression parser for "return" statement
Wolf, Steven
wolfste4 at msu.edu
Mon Nov 14 18:26:42 CET 2016
I stand corrected. I have been chided in the past for not explicitly returning my output by someone claiming it is not best practices.
-Steve
On Mon, 2016-11-14 at 12:22 -0500, Duncan Murdoch wrote:
On 14/11/2016 11:26 AM, Wolf, Steven wrote:
Just to add on a bit, please note that the return is superfluous. If
you write this:
normalDensityFunction = function(x, Mean, Variance) {
# no "return" value given at all
(1/sqrt(2*pi*Variance))*exp(-(1/2)*((x - Mean)^2)/Variance)
}
normalDensityFunction(2,0,1)
...you get the right answer again.
This is not "best practices", and Duncan will probably give you 10
reasons why you should never do it this way. But if the parentheses
behavior bothers you enough, you can subvert it. This probably won't
work so well if you try to make any more complicated output.
Why do you say that's not best practice? I would say that's preferable
to an explicit return().
Duncan
Caveat Emptor.
-SW
[[alternative HTML version deleted]]
More information about the R-help
mailing list