2017-06-13 194 views
2

stringr包提供了很好的字符串函數。R:如何在使用str_detect時忽略大小寫?

要搜索的字符串(不區分大小寫)

一個可以使用

stringr::str_detect('TOYOTA subaru',ignore.case('toyota')) 

這工作,但在警告

請使用(固定|科爾|正則表達式)(X, ignore_case = TRUE)而不是ignore.case(x)

什麼是right wa重寫它?

+0

認爲傾向於避免正則表達式魔術用戶 – userJT

回答

4

可以使用regex(或fix爲@這取決於你所需要的LMO的註釋)功能,使圖案在改性劑或str_detect(見模式參數的指令)詳細介紹:??

library(stringr) 
str_detect('TOYOTA subaru', regex('toyota', ignore_case = T)) 
# [1] TRUE 
+1

或使用'fixed':'str_detect('TOYOTA subaru',fixed('toyota',ignore_case = TRUE))'。 – lmo

1

搜索字符串必須是內部功能fixed和功能具有有效的參數ignore_case

str_detect('TOYOTA subaru', fixed('toyota', ignore_case=TRUE))