Re: [R] Substring replacement in string

2015-03-01 Thread Hervé Pagès
quot; It works even if a variable name starts with a "p": > funnyReplace("pmin(p)", c("pmin", "pmax")) [1] "pmin(1 - P)" and you can specify an arbitrary number of protected words. Cheers, H. Best wishes, Alrik -Ursprüngliche Nach

Re: [R] Substring replacement in string

2015-02-28 Thread Alrik Thiem
--- Von: Hervé Pagès [mailto:hpa...@fredhutch.org] Gesendet: Samstag, 28. Februar 2015 23:29 An: Alrik Thiem; r-help@r-project.org Betreff: Re: [R] Substring replacement in string Hi Alrik, With the Biostrings/IRanges infrastructure (Bioconductor packages), you can do this with: libra

Re: [R] Substring replacement in string

2015-02-28 Thread Hervé Pagès
Hi Alrik, With the Biostrings/IRanges infrastructure (Bioconductor packages), you can do this with: library(Biostrings) x0 <- BString("pmin(pmax(pmin(x1, X2), pmin(X3, X4)) == Y, pmax(Z1, z1))") donttouch_words <- c("pmin", "pmax") ## Extract the substrings to modify (target substring

Re: [R] Substring replacement in string

2015-02-28 Thread Alrik Thiem
Dear Gabor, That works perfectly! Many thanks and best wishes, Alrik -Ursprüngliche Nachricht- Von: Gabor Grothendieck [mailto:ggrothendi...@gmail.com] Gesendet: Samstag, 28. Februar 2015 19:30 An: Alrik Thiem Cc: r-help@r-project.org Betreff: Re: [R] Substring replacement in string

Re: [R] Substring replacement in string

2015-02-28 Thread Gabor Grothendieck
bor Grothendieck [mailto:ggrothendi...@gmail.com] > Gesendet: Samstag, 28. Februar 2015 13:35 > An: Alrik Thiem > Cc: r-help@r-project.org > Betreff: Re: [R] Substring replacement in string > > On Fri, Feb 27, 2015 at 5:19 PM, Alrik Thiem wrote: >> I would like to replace all l

Re: [R] Substring replacement in string

2015-02-28 Thread Alrik Thiem
string, I can then do: > >> tt[pmin(pmax(pmin(1-tt$A,tt$B), >> pmin(1-tt$A,tt$C,1-tt$D))==tt$Y,pmax(tt$E,1-tt$E))==TRUE, ] > A B C D Y E > 1 0 0 0 0 0 0 > 2 0 0 0 0 0 1 > . . . . . . . > 61 1 1 1 1 0 0 > 62 1 1 1 1 0 1 > > -Ursprüngliche Nachricht-

Re: [R] Substring replacement in string

2015-02-28 Thread Michael Dewey
1 . . . . . . . 61 1 1 1 1 0 0 62 1 1 1 1 0 1 -Ursprüngliche Nachricht- Von: Michael Dewey [mailto:i...@aghmed.fsnet.co.uk] Gesendet: Samstag, 28. Februar 2015 14:50 An: Alrik Thiem Cc: r-help@r-project.org Betreff: Re: [R] Substring replacement in string Dear Alrik This may seem a silly sugg

Re: [R] Substring replacement in string

2015-02-28 Thread William Dunlap
*Cc:* r-help@r-project.org > *Betreff:* Re: [R] Substring replacement in string > > > > If your string will always represent an R expression, you could work with > > the expression directly with functions like all.names() and substitute(). > > > > f <- f

Re: [R] Substring replacement in string

2015-02-28 Thread Alrik Thiem
0 0 0 0 0 0 2 0 0 0 0 0 1 . . . . . . . 61 1 1 1 1 0 0 62 1 1 1 1 0 1 -Ursprüngliche Nachricht- Von: Michael Dewey [mailto:i...@aghmed.fsnet.co.uk] Gesendet: Samstag, 28. Februar 2015 14:50 An: Alrik Thiem Cc: r-help@r-project.org Betreff: Re: [R] Substring replacement in string Dear

Re: [R] Substring replacement in string

2015-02-28 Thread Michael Dewey
icht- Von: Gabor Grothendieck [mailto:ggrothendi...@gmail.com] Gesendet: Samstag, 28. Februar 2015 13:35 An: Alrik Thiem Cc: r-help@r-project.org Betreff: Re: [R] Substring replacement in string On Fri, Feb 27, 2015 at 5:19 PM, Alrik Thiem wrote: I would like to replace all lower-case letters in a

Re: [R] Substring replacement in string

2015-02-28 Thread Alrik Thiem
Best wishes, Alrik -Ursprüngliche Nachricht- Von: Gabor Grothendieck [mailto:ggrothendi...@gmail.com] Gesendet: Samstag, 28. Februar 2015 13:35 An: Alrik Thiem Cc: r-help@r-project.org Betreff: Re: [R] Substring replacement in string On Fri, Feb 27, 2015 at 5:19 PM, Alrik Thiem wrot

Re: [R] Substring replacement in string

2015-02-28 Thread Gabor Grothendieck
On Fri, Feb 27, 2015 at 5:19 PM, Alrik Thiem wrote: > I would like to replace all lower-case letters in a string that are not part > of certain fixed expressions. For example, I have the string: > > "pmin(pmax(pmin(x1, X2), pmin(X3, X4)) == Y, pmax(Z1, z1))" > > Where I would like to replace all l

Re: [R] Substring replacement in string

2015-02-27 Thread Alrik Thiem
Thiem Cc: r-help@r-project.org Betreff: Re: [R] Substring replacement in string If your string will always represent an R expression, you could work with the expression directly with functions like all.names() and substitute(). f <- function (expr) { toReplace <- setdiff(all.names(ex

Re: [R] Substring replacement in string

2015-02-27 Thread William Dunlap
If your string will always represent an R expression, you could work with the expression directly with functions like all.names() and substitute(). f <- function (expr) { toReplace <- setdiff(all.names(expr), c("pmin", "pmax")) toReplace <- grep(value = TRUE, "[a-z]", toReplace) names(