So i have a variable set to an sqlite query in R like so:
query<-paste("SELECT ID FROM DataTable WHERE Name = \'", X, "\'", sep="")
xid<-dbGetQuery(conn, query)
if X is in the database, xid is
1 obs. of 1 varaibles
but if X is not in the database, xid is
0 obs of 1 variables
I can't use exists()
, or Length()
or is.integer()
or is.null()
or anything else I can think of to differentiate between them since they both exist, are the same length and aren't null.
I'm sure it's something simple, but i'm new to this (obviously).
Thanks for the help.
dbGetQuery
returns a data frame. In the first case it has one row, so nrow(xid)
should be 1. In the second case it should return a data frame with zero rows, so nrow(xid)
should be zero. Just check the number of rows.