Error in stri_detect_regex in R
I am receiving this error
Error in stri_detect_regex(string, pattern, opts_regex = opts(pattern)) :
Incorrectly nested parentheses in regexp pattern. (U_REGEX_MISMATCHED_PAREN)
when I run the code
# find occurrences of initial dataframe
named_RN$search <- map_int(named_RN$V1, function(x){sum(str_detect(final_RN$named_RN, pattern = x))})
in which named_RN$V1
looks like
aldosterone
renin
potassium
calcitrol
and final_RN$named_RN
looks like
aldosterone, creatinine
human, warfarin
aspirin, renin, calcitrol
magnesium, calcitrol
and my code aims to create a new variable within named_RN
that shows the raw counts of each phrase, so that named_RN
looks like
V1 search
aldosterone 1
renin 0
potassium 0
calcitrol 2
Please advise. Thanks.
r regex dataframe text error-handling
add a comment |
I am receiving this error
Error in stri_detect_regex(string, pattern, opts_regex = opts(pattern)) :
Incorrectly nested parentheses in regexp pattern. (U_REGEX_MISMATCHED_PAREN)
when I run the code
# find occurrences of initial dataframe
named_RN$search <- map_int(named_RN$V1, function(x){sum(str_detect(final_RN$named_RN, pattern = x))})
in which named_RN$V1
looks like
aldosterone
renin
potassium
calcitrol
and final_RN$named_RN
looks like
aldosterone, creatinine
human, warfarin
aspirin, renin, calcitrol
magnesium, calcitrol
and my code aims to create a new variable within named_RN
that shows the raw counts of each phrase, so that named_RN
looks like
V1 search
aldosterone 1
renin 0
potassium 0
calcitrol 2
Please advise. Thanks.
r regex dataframe text error-handling
You got incorrectly nested parentheses in one of the regular expression patterns. Check out e.g.stringr::str_detect(c("a","a("), c("a", "a("))
versusstringr::str_detect(c("a","a("), stringr::fixed(c("a", "a(")))
. Maybe get rid of the parentheses or use fixed matching?
– lukeA
Aug 23 '17 at 1:11
3
If you match using fixed strings, not regex, you really just need to usestr_detect(final_RN$named_RN, fixed(x))
– Wiktor Stribiżew
Aug 23 '17 at 6:19
@Wiktor, that worked! mind posting that as an answer so I can accept it?
– sweetmusicality
Aug 23 '17 at 21:54
add a comment |
I am receiving this error
Error in stri_detect_regex(string, pattern, opts_regex = opts(pattern)) :
Incorrectly nested parentheses in regexp pattern. (U_REGEX_MISMATCHED_PAREN)
when I run the code
# find occurrences of initial dataframe
named_RN$search <- map_int(named_RN$V1, function(x){sum(str_detect(final_RN$named_RN, pattern = x))})
in which named_RN$V1
looks like
aldosterone
renin
potassium
calcitrol
and final_RN$named_RN
looks like
aldosterone, creatinine
human, warfarin
aspirin, renin, calcitrol
magnesium, calcitrol
and my code aims to create a new variable within named_RN
that shows the raw counts of each phrase, so that named_RN
looks like
V1 search
aldosterone 1
renin 0
potassium 0
calcitrol 2
Please advise. Thanks.
r regex dataframe text error-handling
I am receiving this error
Error in stri_detect_regex(string, pattern, opts_regex = opts(pattern)) :
Incorrectly nested parentheses in regexp pattern. (U_REGEX_MISMATCHED_PAREN)
when I run the code
# find occurrences of initial dataframe
named_RN$search <- map_int(named_RN$V1, function(x){sum(str_detect(final_RN$named_RN, pattern = x))})
in which named_RN$V1
looks like
aldosterone
renin
potassium
calcitrol
and final_RN$named_RN
looks like
aldosterone, creatinine
human, warfarin
aspirin, renin, calcitrol
magnesium, calcitrol
and my code aims to create a new variable within named_RN
that shows the raw counts of each phrase, so that named_RN
looks like
V1 search
aldosterone 1
renin 0
potassium 0
calcitrol 2
Please advise. Thanks.
r regex dataframe text error-handling
r regex dataframe text error-handling
asked Aug 23 '17 at 0:49
sweetmusicalitysweetmusicality
536216
536216
You got incorrectly nested parentheses in one of the regular expression patterns. Check out e.g.stringr::str_detect(c("a","a("), c("a", "a("))
versusstringr::str_detect(c("a","a("), stringr::fixed(c("a", "a(")))
. Maybe get rid of the parentheses or use fixed matching?
– lukeA
Aug 23 '17 at 1:11
3
If you match using fixed strings, not regex, you really just need to usestr_detect(final_RN$named_RN, fixed(x))
– Wiktor Stribiżew
Aug 23 '17 at 6:19
@Wiktor, that worked! mind posting that as an answer so I can accept it?
– sweetmusicality
Aug 23 '17 at 21:54
add a comment |
You got incorrectly nested parentheses in one of the regular expression patterns. Check out e.g.stringr::str_detect(c("a","a("), c("a", "a("))
versusstringr::str_detect(c("a","a("), stringr::fixed(c("a", "a(")))
. Maybe get rid of the parentheses or use fixed matching?
– lukeA
Aug 23 '17 at 1:11
3
If you match using fixed strings, not regex, you really just need to usestr_detect(final_RN$named_RN, fixed(x))
– Wiktor Stribiżew
Aug 23 '17 at 6:19
@Wiktor, that worked! mind posting that as an answer so I can accept it?
– sweetmusicality
Aug 23 '17 at 21:54
You got incorrectly nested parentheses in one of the regular expression patterns. Check out e.g.
stringr::str_detect(c("a","a("), c("a", "a("))
versus stringr::str_detect(c("a","a("), stringr::fixed(c("a", "a(")))
. Maybe get rid of the parentheses or use fixed matching?– lukeA
Aug 23 '17 at 1:11
You got incorrectly nested parentheses in one of the regular expression patterns. Check out e.g.
stringr::str_detect(c("a","a("), c("a", "a("))
versus stringr::str_detect(c("a","a("), stringr::fixed(c("a", "a(")))
. Maybe get rid of the parentheses or use fixed matching?– lukeA
Aug 23 '17 at 1:11
3
3
If you match using fixed strings, not regex, you really just need to use
str_detect(final_RN$named_RN, fixed(x))
– Wiktor Stribiżew
Aug 23 '17 at 6:19
If you match using fixed strings, not regex, you really just need to use
str_detect(final_RN$named_RN, fixed(x))
– Wiktor Stribiżew
Aug 23 '17 at 6:19
@Wiktor, that worked! mind posting that as an answer so I can accept it?
– sweetmusicality
Aug 23 '17 at 21:54
@Wiktor, that worked! mind posting that as an answer so I can accept it?
– sweetmusicality
Aug 23 '17 at 21:54
add a comment |
1 Answer
1
active
oldest
votes
Since you are using fixed strings, not regular expressions, you need to tell the regex engine to use the patterns as plain, literal text. You can use it like this:
str_detect(final_RN$named_RN, fixed(x))
^^^^^^^^
See "Fixed matches":
fixed(x)
only matches the exact sequence of bytes specified byx
. This is a very limited “pattern”, but the restriction can make matching much faster.
You might also consider coll(x)
in case you want to use human-language collation rules while performing a case insensitive search.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f45828985%2ferror-in-stri-detect-regex-in-r%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Since you are using fixed strings, not regular expressions, you need to tell the regex engine to use the patterns as plain, literal text. You can use it like this:
str_detect(final_RN$named_RN, fixed(x))
^^^^^^^^
See "Fixed matches":
fixed(x)
only matches the exact sequence of bytes specified byx
. This is a very limited “pattern”, but the restriction can make matching much faster.
You might also consider coll(x)
in case you want to use human-language collation rules while performing a case insensitive search.
add a comment |
Since you are using fixed strings, not regular expressions, you need to tell the regex engine to use the patterns as plain, literal text. You can use it like this:
str_detect(final_RN$named_RN, fixed(x))
^^^^^^^^
See "Fixed matches":
fixed(x)
only matches the exact sequence of bytes specified byx
. This is a very limited “pattern”, but the restriction can make matching much faster.
You might also consider coll(x)
in case you want to use human-language collation rules while performing a case insensitive search.
add a comment |
Since you are using fixed strings, not regular expressions, you need to tell the regex engine to use the patterns as plain, literal text. You can use it like this:
str_detect(final_RN$named_RN, fixed(x))
^^^^^^^^
See "Fixed matches":
fixed(x)
only matches the exact sequence of bytes specified byx
. This is a very limited “pattern”, but the restriction can make matching much faster.
You might also consider coll(x)
in case you want to use human-language collation rules while performing a case insensitive search.
Since you are using fixed strings, not regular expressions, you need to tell the regex engine to use the patterns as plain, literal text. You can use it like this:
str_detect(final_RN$named_RN, fixed(x))
^^^^^^^^
See "Fixed matches":
fixed(x)
only matches the exact sequence of bytes specified byx
. This is a very limited “pattern”, but the restriction can make matching much faster.
You might also consider coll(x)
in case you want to use human-language collation rules while performing a case insensitive search.
edited Jan 25 at 10:20
answered Aug 23 '17 at 21:56
Wiktor StribiżewWiktor Stribiżew
315k16133214
315k16133214
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f45828985%2ferror-in-stri-detect-regex-in-r%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You got incorrectly nested parentheses in one of the regular expression patterns. Check out e.g.
stringr::str_detect(c("a","a("), c("a", "a("))
versusstringr::str_detect(c("a","a("), stringr::fixed(c("a", "a(")))
. Maybe get rid of the parentheses or use fixed matching?– lukeA
Aug 23 '17 at 1:11
3
If you match using fixed strings, not regex, you really just need to use
str_detect(final_RN$named_RN, fixed(x))
– Wiktor Stribiżew
Aug 23 '17 at 6:19
@Wiktor, that worked! mind posting that as an answer so I can accept it?
– sweetmusicality
Aug 23 '17 at 21:54