1

I have the following mySQL query:

"select * from data WHERE TEXT RLIKE '[[:<:]]digital[[:>:]]' OR TEXT RLIKE '[[:<:]]data[[:>:]]' OR TEXT RLIKE '[[:<:]]agile[[:>:]]' OR (TEXT RLIKE '[[:<:]]self[[:>:]]' AND TEXT RLIKE '[[:<:]]service[[:>:]]') OR TEXT RLIKE '[[:<:]]cloud[[:>:]]' OR TEXT RLIKE '[[:<:]]insight[^[:space:]]+[[:>:]]' OR TEXT RLIKE '[[:<:]]modern[^[:space:]]+[[:>:]]'")

I want to apply this in R using the sqldf package:

sqldf( "select * from data WHERE TEXT RLIKE '[[:<:]]digital[[:>:]]' OR TEXT RLIKE '[[:<:]]data[[:>:]]' OR TEXT RLIKE '[[:<:]]agile[[:>:]]' OR (TEXT RLIKE '[[:<:]]self[[:>:]]' AND TEXT RLIKE '[[:<:]]service[[:>:]]') OR TEXT RLIKE '[[:<:]]cloud[[:>:]]' OR TEXT RLIKE '[[:<:]]insight[^[:space:]]+[[:>:]]' OR TEXT RLIKE '[[:<:]]modern[^[:space:]]+[[:>:]]'")

that I want to run against some sample data:

data <- structure(list(Participant = 1:3, A = c("and other agile digital, things", "testing test and modern", "nothing here"), B = c("", "b", "b"), C = c("c", "c", "c")), .Names = c("Participant", "TEXT", "other", "another"), row.names = c(NA, -3L), class = "data.frame")

I get the following error

Error in sqliteSendQuery(con, statement, bind.data) : error in statement: near "RLIKE": syntax error

It seems like this package doesn't like RLIKE statements. Why, and how do I get around this?

lmcshane
  • 1,074
  • 4
  • 14
  • 27

1 Answers1

2

It is always good to include the desired result. Based on this source it looks like you want to extract the rows where in the TEXT-column foo is followed by a non-space character.

You can also do this quite simply in R with grep-function:

dat[grep('.*(foo)[^ ]', dat$TEXT),]

which gives:

  Participant                  TEXT other another
1           1 and other foo, things             c

PS: it is better not to give your dataset the same name as a function; for that reason I used dat instead of data

Jaap
  • 81,064
  • 34
  • 182
  • 193