{"action":"created","issue":{"url":"https://api.github.com/repos/STAT545-UBC/Discussion/issues/226","labels_url":"https://api.github.com/repos/STAT545-UBC/Discussion/issues/226/labels{/name}","comments_url":"https://api.github.com/repos/STAT545-UBC/Discussion/issues/226/comments","events_url":"https://api.github.com/repos/STAT545-UBC/Discussion/issues/226/events","html_url":"https://github.com/STAT545-UBC/Discussion/issues/226","id":115359020,"number":226,"title":"Regular Expressions and R","user":{"login":"AdrianLJones","id":14188583,"avatar_url":"https://avatars.githubusercontent.com/u/14188583?v=3","gravatar_id":"","url":"https://api.github.com/users/AdrianLJones","html_url":"https://github.com/AdrianLJones","followers_url":"https://api.github.com/users/AdrianLJones/followers","following_url":"https://api.github.com/users/AdrianLJones/following{/other_user}","gists_url":"https://api.github.com/users/AdrianLJones/gists{/gist_id}","starred_url":"https://api.github.com/users/AdrianLJones/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AdrianLJones/subscriptions","organizations_url":"https://api.github.com/users/AdrianLJones/orgs","repos_url":"https://api.github.com/users/AdrianLJones/repos","events_url":"https://api.github.com/users/AdrianLJones/events{/privacy}","received_events_url":"https://api.github.com/users/AdrianLJones/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-11-05T19:44:04Z","updated_at":"2015-11-06T06:33:08Z","closed_at":null,"body":"Is there some particularity to the syntax for R that I don't know about?\r\n\r\nIn the [Regex tester](https://regex101.com/r/gZ2uW4/2) I put in `\\D|\\d{3,}` with the idea of selecting all characters or digits that are longer than length one or two.  My plan was to turn those to null as a way to clean the Age variable in the candy data set, and this seemed to work in the test bed.\r\n\r\nBut when I try 'candy_age_time <- candy_age_time %>% mutate(clean.Age = gsub(\"\\D|\\d{3,}\", '', Age))'\r\nI get `Error: '\\D' is an unrecognized escape in character string starting \"\"\\D\"`\r\n\r\nWhat is going wrong?\r\n\r\nThanks,\r\n\r\nAdrian"},"comment":{"url":"https://api.github.com/repos/STAT545-UBC/Discussion/issues/comments/154324410","html_url":"https://github.com/STAT545-UBC/Discussion/issues/226#issuecomment-154324410","issue_url":"https://api.github.com/repos/STAT545-UBC/Discussion/issues/226","id":154324410,"user":{"login":"ksamuk","id":8412607,"avatar_url":"https://avatars.githubusercontent.com/u/8412607?v=3","gravatar_id":"","url":"https://api.github.com/users/ksamuk","html_url":"https://github.com/ksamuk","followers_url":"https://api.github.com/users/ksamuk/followers","following_url":"https://api.github.com/users/ksamuk/following{/other_user}","gists_url":"https://api.github.com/users/ksamuk/gists{/gist_id}","starred_url":"https://api.github.com/users/ksamuk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ksamuk/subscriptions","organizations_url":"https://api.github.com/users/ksamuk/orgs","repos_url":"https://api.github.com/users/ksamuk/repos","events_url":"https://api.github.com/users/ksamuk/events{/privacy}","received_events_url":"https://api.github.com/users/ksamuk/received_events","type":"User","site_admin":false},"created_at":"2015-11-06T06:33:08Z","updated_at":"2015-11-06T06:33:08Z","body":"This is going to be unsatisfying, but I've never been able to get the \\\\w \\\\d family of character classes to work as part of another bracketed character class (like your example which is \\\\d and \",\"). In those cases, you can use `[:digit:]` or just `0-9` (less typing!) like:\r\n\r\n```{r}\r\n> grep(\"^[,0-9]+$\", c(letters, \"123\", \"1,234\", \"mints\"), value = TRUE)\r\n[1] \"123\"   \"1,234\"\r\n> grep(\"^[,[:digit:]]+$\", c(letters, \"123\", \"1,234\", \"mints\"), value = TRUE)\r\n[1] \"123\"   \"1,234\"\r\n```\r\n\r\nI think that problem might be related to the fact that items in square brackets are interpreted literally, e.g. `[*]` matches a literal asterix. It would then maybe make sense that in square brackets you would only have to single escape the `\\d`, but that also doesn't work. "}}