Hi, I'm running R 3.2.1 and im having an unexpected problem... when I run the follwing code it returns an error library(stringr) str_extract("+proj=utm +zone=19 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0", "+proj=[a-zA-Z0-9]*") But I can't find whats wrong with my code. Thanks Mauricio [[alternative HTML version deleted]]
Hi, The + is a special character in regular expressions. If you want to match a literal + you need to escape it: str_extract("+proj=utm +zone=19 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0", "\\+proj=[a-zA-Z0-9]*") Sarah On Thu, Aug 13, 2015 at 2:55 PM, Mauricio Romero <mauricioromerolondono at gmail.com> wrote:> Hi, > > I'm running R 3.2.1 and im having an unexpected problem... when I run the > follwing code it returns an error > > library(stringr) > str_extract("+proj=utm +zone=19 +datum=WGS84 +units=m +no_defs +ellps=WGS84 > +towgs84=0,0,0", "+proj=[a-zA-Z0-9]*") > > But I can't find whats wrong with my code. > > Thanks > > Mauricio >
thanks.... that makes sense... in the previous version of R it worked for some reason. On Thu, Aug 13, 2015 at 4:33 PM, Sarah Goslee <sarah.goslee at gmail.com> wrote:> Hi, > > The + is a special character in regular expressions. If you want to > match a literal + you need to escape it: > > str_extract("+proj=utm +zone=19 +datum=WGS84 +units=m +no_defs > +ellps=WGS84 +towgs84=0,0,0", "\\+proj=[a-zA-Z0-9]*") > > Sarah > > > On Thu, Aug 13, 2015 at 2:55 PM, Mauricio Romero > <mauricioromerolondono at gmail.com> wrote: > > Hi, > > > > I'm running R 3.2.1 and im having an unexpected problem... when I run the > > follwing code it returns an error > > > > library(stringr) > > str_extract("+proj=utm +zone=19 +datum=WGS84 +units=m +no_defs > +ellps=WGS84 > > +towgs84=0,0,0", "+proj=[a-zA-Z0-9]*") > > > > But I can't find whats wrong with my code. > > > > Thanks > > > > Mauricio > > >[[alternative HTML version deleted]]
"+" is a special character in regular expressions that requires a preceding pattern to apply to. See ?base::regex. You need to escape the special with a backslash to remove the special behavior, and escape the backslash so the R parser will be happy. str_extract("+proj=utm +zone=19 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0", "\\+proj=[a-zA-Z0-9]*") Please read and follow the Posting Guide, including sending your emails using plain text instead of HTML. --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. On August 13, 2015 11:55:36 AM PDT, Mauricio Romero <mauricioromerolondono at gmail.com> wrote:>Hi, > >I'm running R 3.2.1 and im having an unexpected problem... when I run >the >follwing code it returns an error > >library(stringr) >str_extract("+proj=utm +zone=19 +datum=WGS84 +units=m +no_defs >+ellps=WGS84 >+towgs84=0,0,0", "+proj=[a-zA-Z0-9]*") > >But I can't find whats wrong with my code. > >Thanks > >Mauricio > > [[alternative HTML version deleted]] > >______________________________________________ >R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.