How do I remove a "$" character from a string sub() and gsub() with "$" or "\$" as pattern do not work.> sub("$","","ABC$DEF")[1] "ABC$DEF"> sub("\$","","ABC$DEF")Error: '\$' is an unrecognized escape in character string starting "\$"> sub(\$,"","ABC$DEF")Error: unexpected input in "sub(\" Thanks -- Nevil Amos Molecular Ecology Research Group Australian Centre for Biodiversity Monash University CLAYTON VIC 3800 Australia [[alternative HTML version deleted]]
Hi guys, I have a question. I am running 3 R sessions simultaneously for different analysis. I found out that when R quit, only objects in one of these sessions was saved in the work space. How can I save objects of all 3 R sessions? Thank you very much. YA
Dear Nevil, You have the escape the backslash:> sub("\\$", "", "ABC$DEF")[1] "ABCDEF" I hope this helps, John ------------------------------------------------ John Fox Sen. William McMaster Prof. of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox/ On Tue, 10 Apr 2012 21:34:13 +1000 Nevil Amos <nevil.amos at monash.edu> wrote:> How do I remove a "$" character from a string sub() and gsub() with "$" or > "\$" as pattern do not work. > > sub("$","","ABC$DEF") > [1] "ABC$DEF" > > sub("\$","","ABC$DEF") > Error: '\$' is an unrecognized escape in character string starting "\$" > > sub(\$,"","ABC$DEF") > Error: unexpected input in "sub(\" > > Thanks > -- > Nevil Amos > Molecular Ecology Research Group > Australian Centre for Biodiversity > Monash University > CLAYTON VIC 3800 > Australia > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > 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.
On 10-Apr-2012 11:34:13 Nevil Amos wrote:> How do I remove a "$" character from a string sub() and gsub() with "$" or > "\$" as pattern do not work. >> sub("$","","ABC$DEF") > [1] "ABC$DEF" >> sub("\$","","ABC$DEF") > Error: '\$' is an unrecognized escape in character string starting "\$" >> sub(\$,"","ABC$DEF") > Error: unexpected input in "sub(\" > > Thanks > -- > Nevil Amos > Molecular Ecology Research Group > Australian Centre for Biodiversity > Monash University > CLAYTON VIC 3800 > Australiasub("\\$","","ABC$DEF") # [1] "ABCDEF" Logic: "$" is a metacharacter which stands for "the end of the thing"; as a check of that, instead of your sub("$","","ABC$DEF") do sub("$","+","ABC$DEF") # [1] "ABC$DEF+" Therefore "$" needs to be escaped, so you have to use "\"; but since "\" is itself a metacharacter you have to escape that too, hence "\\$". Hoping this hrelps, Ted. ------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at wlandres.net> Date: 10-Apr-2012 Time: 12:46:59 This message was sent by XFMail
Hi, Try with a double back slash: sub("\\$","","ABC$DEF") HTH, Ivan -- Ivan CALANDRA Universit? de Bourgogne UMR CNRS/uB 6282 Biog?osciences 6 Boulevard Gabriel 21000 Dijon, FRANCE +33(0)3.80.39.63.06 ivan.calandra at u-bourgogne.fr http://biogeosciences.u-bourgogne.fr/calandra Le 10/04/12 13:34, Nevil Amos a ?crit :> How do I remove a "$" character from a string sub() and gsub() with "$" or > "\$" as pattern do not work. >> sub("$","","ABC$DEF") > [1] "ABC$DEF" >> sub("\$","","ABC$DEF") > Error: '\$' is an unrecognized escape in character string starting "\$" >> sub(\$,"","ABC$DEF") > Error: unexpected input in "sub(\" > > Thanks
Best I understand it yes: I'm not sure if there's an easy way to combine sessions beyond loading them all into a single session and then saving that. Michael On Tue, Apr 10, 2012 at 8:01 AM, ya <xinxi813 at 163.com> wrote:> so, objects in 3 different sessions would be saved separately into 3 > different R image file? > > > > On 2012-4-10 14:54, R. Michael Weylandt <michael.weylandt at gmail.com> wrote: >> >> You'll need to save them manually to avoid name conflicts -- save.image() >> is the function to do so but you need to give a file name. >> >> Michael >> >> On Apr 10, 2012, at 7:41 AM, ya<xinxi813 at 163.com> ?wrote: >> >>> Hi guys, >>> >>> I have a question. I am running 3 R sessions simultaneously for different >>> analysis. I found out that when R quit, only objects in one of these >>> sessions was saved in the work space. How can I save objects of all 3 R >>> sessions? >>> >>> Thank you very much. >>> >>> YA >>> >>> ______________________________________________ >>> R-help at r-project.org mailing list >>> 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. > > >
On Tue, Apr 10, 2012 at 7:34 AM, Nevil Amos <nevil.amos at monash.edu> wrote:> How do I remove a "$" character from a string sub() and gsub() with "$" or > "\$" as pattern do not work. >> sub("$","","ABC$DEF") > [1] "ABC$DEF" >> sub("\$","","ABC$DEF") > Error: '\$' is an unrecognized escape in character string starting "\$" >> sub(\$,"","ABC$DEF") > Error: unexpected input in "sub(\" >Here are three ways: sub("$", "", "ABC$DEF", fixed = TRUE) sub("\\$", "", "ABC$DEF") sub("[$]", "", "ABC$DEF") -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com
In data marted? 10 aprile 2012 13:34:13, Nevil Amos ha scritto:> How do I remove a "$" character from a string sub() and gsub() with "$" or > "\$" as pattern do not work. > > > sub("$","","ABC$DEF") > > [1] "ABC$DEF" > > > sub("\$","","ABC$DEF") > > Error: '\$' is an unrecognized escape in character string starting "\$" > > > sub(\$,"","ABC$DEF") > > Error: unexpected input in "sub(\" > > ThanksYou just need a double backslash:> sub("\\$","","ABC$DEF")[1] "ABCDEF"
Maybe Matching Threads
- removeing only rows/columns with "na" value from square ( symmetrical ) matrix.
- Vegan(ordistep) error: Error in if (aod[1, 5] <= Pin) { : missing value where TRUE/FALSE needed
- Geneland error on unix: Error in MCMC(........ :, unused argument(s) (ploidy = 2, genotypes = geno)
- replacing "+" in string
- How to replace all <NA> values in a data.frame with another ( not 0) value