Skip to content
Prev 13030 / 63424 Next

Top-level code in packages

On Fri, 2 Jul 2004, Frank E Harrell Jr wrote:

            
That _is_ a top-level assignment. `Defining' a function is actually
assigning a value to a symbol, and code inside if, for, etc is executed at
top level.

I prefer to write

foo <- if(tools:::.OStype() == "windows") {...} else {...}

for conditional `definitions' precisely because it is clearer that is what 
is going on.

BTW, if you want to test the OS you can't do it with .Platform$OS.type and
allow cross-building, hence the test illustrated.