You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I like the %like% operator in data.table quite a lot as I'm used to SQL queries. In PostgreSQL there is also the ILIKE option where the i stands for case-insensitive.
What do you think of including %ilike% into data.table?
To include this into data.table I would create an operator %ilike% in ilike.R based on like.R adding ignore.case = TRUE to the grep() calls as follows:
ilike<-function(vector, pattern)
{
# Intended for use with a data.table 'where'# Don't use * or % like SQL's like. Uses regexpr syntax - more powerful.if (is.factor(vector)) {
as.integer(vector) %in% grep(pattern,levels(vector), ignore.case=TRUE)
} else {
# most usually character, but integer and numerics will be silently coerced by grepl
grepl(pattern,vector, ignore.case=TRUE)
}
# returns 'logical' so can be combined with other where clauses.
}
"%ilike%"=ilike
reproducible example:
require(data.table)
cars= data.table(cars= rownames(mtcars), mtcars)
cars[ cars %like% 'fiat' ] # no case-insensitive search possiblecars[ grep('fiat', cars, ignore.case=TRUE) ] # using comparably long grepcars[ cars %ilike% 'fiat' ] # the new %ilike%
The text was updated successfully, but these errors were encountered:
True that works as well, wasn't aware of such a regex. Nevertheless %ilike% seems a more intuitive to me. Maybe because I know PostgreSQL. Overall this is a question of coding style anyway.
@andreasLD thanks again for raising. You probably saw since you commented there as well but noting for the record that this was closed in #3333 and #3552
I like the
%like%
operator in data.table quite a lot as I'm used to SQL queries. In PostgreSQL there is also the ILIKE option where the i stands for case-insensitive.What do you think of including
%ilike%
into data.table?To include this into data.table I would create an operator
%ilike%
in ilike.R based on like.R addingignore.case = TRUE
to thegrep()
calls as follows:reproducible example:
The text was updated successfully, but these errors were encountered: