I would like to create a function that can deal with an object that may or may not have been created yet.
At the beginning of this function, I would like to have a quick “if” statement declaring if a certain variable has been created yet. In this case, a time stamp.
TS<-date()
fun<-function(){
if(TS=="")
{print("No Time Stamp Info")}
else
{print("Time Stamp created at"); TS}
}
or alternatively
TS<-date()
fun<-function(){
if(is.character(TS))
{print("Time Stamp created at"); TS}
else
{print("No Time Stamp Info")}
}
But of course if we remove the time stamp and just have the following without first assigning any value to TS:
#TS<-date()
fun<-function(){
if(TS=="")
{print("No Time Stamp Info")}
else
{print("Time Stamp created at"); TS}
}
Than I throw an error because TS does not exist. I would like to find a way so that if there is no variable “TS” in the R workspace, I get the “No Time Stamp Info” , as opposed to an error
Is there anyway to correctly set up a function that can do this?
What about:
this will return
TRUEifTSexists.