Alph
Alph

Reputation: 391

if (TRUE) condition before a function definition

I have some R code that has if (TRUE) before a function begins. What is the purpose of that conditional statement?

if (TRUE) {
    f <- function(x, y) {
        z <- x + y
        z
    }
    f(2, 3)
}

Upvotes: 0

Views: 73

Answers (1)

lefft
lefft

Reputation: 2105

Sometimes people will wrap blocks of code ... in if (FALSE){ ... } if they want to execute a whole script in one shot but are still working on the stuff in .... So seems plausible that whoever wrote it was satisfied enough with ... that they want it to be executed whenever they source the script. (changing FALSE to TRUE is basically the same thing as just deleting the conditional)

Just a guess but that could explain it!

Upvotes: 2

Related Questions