The code right now only sees one value, which is 0. If you don’t don’t give the if statement a value to compare then it simply defaults to the else statement (As is my understanding but I could be wrong on this).Ĭonsole.log("The first number is even!") Furthermore I'm not particularly attached to these ifelse methods for Rle objects (they provide very little value) so I'm fine with removing them.Well you have to remember we are dealing with an if statement, if statements are designed so you can compare values. Said otherwise, when the test argument has a length > 1 (the legitimate case for using ifelse), it doesn't seem like a good idea to rely on one of the yes or no argument to remain non-evaluated.Īnyway, I agree that no package should modify the semantic of the base stuff. Note however that code that relies on one of the yes or no argument to remain non-evaluated is VERY LIKELY to be code that should have used if else instead of ifelse(). Most of the case, this won't have any practical consequences but for ifelse() it does have consequences. More generally speaking, turning a base function into an S4 generic and defining methods for it can potentially modify its semantic since the method dispatch mechanism can decide to evaluate some of the arguments that would have otherwise remained non-evaluated. Yes defining ifelse methods for Rle objects changes the semantic of the function when called on non-Rle objects. I moved them from IRanges to S4Vectors when I did the IRanges/S4Vectors split. These methods were added a long time ago when Rle objects were implemented in IRanges. If this is too much of an annoyance we could also get rid of the ifelse methods for Rle objects defined in S4Vectors: > showMethods("ifelse") See this recommendation from Martin Maechler: One workaround is for you to use if else instead. ‘yes’ will be evaluated if and only if any element of ‘test’ is true, and analogously for ‘no’. I understand this changes a little bit the contract of the ifelse() function. As a result, the arguments passed to it get evaluated before dispatch can happen, like for any generic function. Loaded via a namespace (and not attached):Īll S4Vectors is doing is turning ifelse() into a generic function with dispatch on its 3 arguments. parallel stats4 stats graphics grDevices utils datasets LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 This means that even though the 'test' in the ifelse is FALSE, the yes argument is evaluated. The second call to testFnc, after loading S4Vectors, produces the following output:Įrror in ifelse(is.null(universalColors), colors, "grey") :Įrror in evaluating the argument 'yes' in selecting a method for function 'ifelse': Error: argument "colors" is missing, with no default The first call to testFnc produces the expected result: MEs1 = testFnc(expr1, universalColors = labels1) Grey = ifelse(is.null(universalColors), colors, "grey")) TestFnc = function(exprData, colors, universalColors = NULL, Here's the example code (maybe not the simplest, but hopefully simple enough): which seems to break the ifelse function. I stumbled upon a weirdness caused by loading of package S4Vectors.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |