Created
September 6, 2014 00:25
-
-
Save johnmyleswhite/fe3b89a20640fe154a20 to your computer and use it in GitHub Desktop.
Type instability when using "generic" NA value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> type.unstable <- function(x) { | |
+ if (x > 0) { | |
+ return("foo") | |
+ } else { | |
+ return(NA) | |
+ } | |
+ } | |
> | |
> class(type.unstable(0)) | |
[1] "logical" | |
> class(type.unstable(1)) | |
[1] "character" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How about this:
Or more advanced typing: