Last active
August 29, 2015 14:14
-
-
Save Krewn/732964a9c02336aeb4ff to your computer and use it in GitHub Desktop.
Check to see if an array element exists and returning a boolean.
This file contains hidden or 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
| newPointer=function(inputValue){ # see : http://www.stat.berkeley.edu/~paciorek/computingTips/Pointers_passing_reference_.html | |
| object=new.env(parent=globalenv()) | |
| object$value=inputValue | |
| class(object)='pointer' | |
| return(object) | |
| } | |
| exDb <- function(t,i,v = F){#Check if element i exists in t | |
| r = F | |
| tryCatch({ | |
| temp <- newPointer(t[[i]]) # Attempt to access variable location in question | |
| if(is.null(temp$value)){r = F}else{r = T} #If the prior line of code passes without error it is assured that the value exists but is it null? | |
| }, error = function(e){ | |
| if(v){print(paste('Warning:',e))}#Lets you know the error | |
| r = F #sets return value to False | |
| }) | |
| return(r) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment