implicit return? [R for BE/BA]

posted by ElMaestro  – Belgium?, 2019-04-29 09:40 (510 d 20:43 ago) – Posting: # 20260
Views: 4,175

Hi Hötzi,


Interestingly (at least to moi!), I tried out of curiosity to do this:

QWERTY=function(x)
{
 ifelse ((x==0), "foo", "bar")
}


The benchmark for this version is much, much slower than any of the other proposals (at least on my system). Another example that shows that condensing code towards fewer keystrokes is not always fastest. I wonder what goes on internally since this is much slower? Perhaps space is allocated for both "foo" and "bar" in memory and then there is a decision as to which one to throw away and which one to keep on the CPU stack? I don't have a very good at understanding of these things.

This one is appearing even worse:
QWERTY2=function(x)
{
 ifelse (x, "bar", "foo")
}


I have no idea why QWERTY2 would not outperform QWERTY or at least be the same if R has a kind of optimiser in the interpreter. Would you happen know????

I could be wrong, but...

Best regards,
ElMaestro

R's base package has 274 reserved words and operators, along with 1761 functions. I can use 18 of them (about 14 of them properly). I believe this makes me the Donald Trump of programming.

Complete thread:

Activity
 Admin contact
21,068 posts in 4,392 threads, 1,465 registered users;
online 13 (0 registered, 13 guests [including 7 identified bots]).
Forum time: Monday 06:23 CEST (Europe/Vienna)

I have finally come to the konklusion
that a good reliable set ov bowels
iz worth more to a man
than enny quantity of brains.    Josh Billings

The Bioequivalence and Bioavailability Forum is hosted by
BEBAC Ing. Helmut Schütz
HTML5