Error in stri_detect_regex in R












2















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.










share|improve this question























  • 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





    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
















2















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.










share|improve this question























  • 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





    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














2












2








2








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.










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Aug 23 '17 at 0:49









sweetmusicalitysweetmusicality

536215




536215













  • 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





    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



















  • 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





    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

















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












1 Answer
1






active

oldest

votes


















2














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 by x. 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.






share|improve this answer

























    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    2














    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 by x. 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.






    share|improve this answer






























      2














      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 by x. 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.






      share|improve this answer




























        2












        2








        2







        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 by x. 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.






        share|improve this answer















        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 by x. 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.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 25 at 10:20

























        answered Aug 23 '17 at 21:56









        Wiktor StribiżewWiktor Stribiżew

        313k16133210




        313k16133210






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Xamarin.iOS Cant Deploy on Iphone

            Glorious Revolution

            Dulmage-Mendelsohn matrix decomposition in Python