Re: [R] Substring replacement in string

2015-02-28 Thread Alrik Thiem
Dear Hervé,

Many thanks for your suggestion. Gabor Grothendieck proposed a simple
one-liner that works perfectly for my purposes:

gsub("(\\b[a-oq-z][a-z0-9]*)", "1-\\U\\1", x, perl = TRUE)

where x is the respective string.

Best wishes,
Alrik

-Ursprüngliche Nachricht-
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:

   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 substrings).
   donttouch_regions <- reduce(do.call("c", lapply(donttouch_words, 
matchPattern, x0)))
   target_regions <- ranges(gaps(donttouch_regions))
   target_substrings <- extractAt(x0, target_regions)

   ## Modify them.
   old <- paste0(letters, collapse="")
   new <- paste0(LETTERS, collapse="")
   target_substrings <- chartr(old, new, target_substrings)

   ## Replace in original string.
   x1 <- replaceAt(x0, target_regions, target_substrings)

Then:

   > x1
 57-letter "BString" instance
   seq: pmin(pmax(pmin(X1, X2), pmin(X3, X4)) == Y, pmax(Z1, Z1))

   > as.character(x1)
   [1] "pmin(pmax(pmin(X1, X2), pmin(X3, X4)) == Y, pmax(Z1, Z1))"

Hope this helps,
H.

On 02/27/2015 02:19 PM, Alrik Thiem wrote:
> Dear R-help list,
>
> 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 lower-case letters that do not belong to
> the functions "pmin" and "pmax" by 1 - toupper(...) to get
>
> "pmin(pmax(pmin(1 - X1, X2), pmin(X3, X4)) == Y, pmax(Z1, 1 - Z1))"
>
> Any ideas on how I could achieve that?
>
> Many thanks and best wishes,
>
> Alrik
>
>
> 
> Alrik Thiem
> Post-Doctoral Researcher
>
> Department of Philosophy
> University of Geneva
> Rue de Candolle 2
> CH-1211 Geneva
>
> +41 76 527 80 83
>
> http://www.alrik-thiem.net
> http://www.compasss.org
>
> __
> R-help@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.
>

-- 
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: hpa...@fredhutch.org
Phone:  (206) 667-5791
Fax:(206) 667-1319

__
R-help@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.


Re: [R] r script in web

2015-02-28 Thread Jeff Newmiller
I cannot see how that would be possible. R must be installed in order to use it.
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

On February 28, 2015 12:29:17 PM PST, hamid-reza kadkhodazadeh 
 wrote:
>hi
>i want to run r script in web without install r on server(my server is
>windows).
>is it possible?how?
>
>thank you
>
>   [[alternative HTML version deleted]]
>
>__
>R-help@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.

__
R-help@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.


Re: [R] Firefox not showing R help.

2015-02-28 Thread Rolf Turner


See inline below.

On 01/03/15 10:59, Duncan Murdoch wrote:

On 28/02/2015 4:10 PM, Rolf Turner wrote:


Firefox recently updated itself on my laptop.  Now when I ask for R help
--- e.g. ?plot --- I just get my home page. And no help. If I do "?plot"
again after Firefox has opened its window, I just get yet another
Firefox window, opened to my home page.  (I have my preferences set to

  "When Firefox starts Show my homepage"

--- as I always have had in the past.)


I would guess that browseURL() won't work for any URL.  Is that right?


Yes.  That is correct. E.g. if I do

browseURL("http://www.r-project.org/";)

I get taken to my home page, rather than to the R home page.



What does getOption("browser") give you in R?


"/usr/bin/firefox"


If it is just a character
string (e.g. "xdg-open" is what I get in Ubuntu), does it work from your
command line, outside of R, e.g. for me that test would be

xdg-open http://www.r-project.org


I tried

   /usr/bin/firefox http://www.r-project.org/

from the Linux command line and was taken to the R home page, 
seamlessly.  I also tried


xdg-open http://www.r-project.org/

and that worked equally well.

Finally I tried

options(browser="xdg-open")

and then

?plot

and BINGO!!! the HTML help came up as requested.

So I have a working solution to my problem.  But I *really* don't 
understand why changing the browser from "/usr/bin/firefox" to 
"xdg-open" made a difference.  (Since there appears to be no difference 
at the Linux command line.)


Anyway; thanks very much for solving my problem.

cheers,

Rolf



If that doesn't work, but you can figure out a command line way to open
a particular URL, change getOption("browser") to use that.

Duncan Murdoch



The Firefox that I am currently running is (according Firefox help
--> "About Firefox") is version 36.0.

Can anyone suggest to me how I can get my html R help back?

For what it's worth:  I am using Linux, Fedora 17.  (Yes, I know it's
elderly, but then so am I. :-) )

Also in case it has any relevance:


sessionInfo()

R version 3.1.2 (2014-10-31)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
  [1] LC_CTYPE=en_NZ.utf8   LC_NUMERIC=C
  [3] LC_TIME=en_NZ.utf8LC_COLLATE=en_NZ.utf8
  [5] LC_MONETARY=en_NZ.utf8LC_MESSAGES=en_NZ.utf8
  [7] LC_PAPER=en_NZ.utf8   LC_NAME=C
  [9] LC_ADDRESS=C  LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_NZ.utf8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

other attached packages:
[1] spatstat_1.40-0.064 misc_0.0-16

loaded via a namespace (and not attached):
  [1] abind_1.4-0 deldir_0.1-7goftest_1.0-2   grid_3.1.2
  [5] lattice_0.20-29 Matrix_1.1-4mgcv_1.8-3  nlme_3.1-118
  [9] polyclip_1.3-1  tensor_1.5  tools_3.1.2



--
Rolf Turner
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276
Home phone: +64-9-480-4619

__
R-help@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.


Re: [R] Lubridate and NameSpace

2015-02-28 Thread Roy Mendelssohn - NOAA Federal
Not certain but perhaps:

>  lubridate::%m+%

there is a subtle difference between what the two and three colons do.

-Roy

On Feb 28, 2015, at 9:25 AM, Glenn Schultz  wrote:

> Hello All,
> 
> I am working on a package very near completion - roxygenizing it now.  The 
> namespace imports from lubridate importFrom(lubridate,"%m+%").  The problem 
> is:
> 
> Lubridate will not load with bondlab, I have to manually click on lubridate 
> in R Studio to load it
> I tried calling function using lubridate:::%m+% within my function based on 
> some discussion I found online.  This is likely the correct idea but I don't 
> think I am calling the function correctly since it does not work in the code 
> when I use the above syntax.
> Any suggestions are appreciated>
> 
> Best Glenn 
> 
> The description file is as follows: 
> 
> Package: BondLab
> Type: Package
> Title: A package for the analysis of structured products
> Version: 0.0.0
> Date: 2013-12-08
> Author: Glenn Schultz, CFA
> Maintainer: Glenn Schultz 
> Description: The package provides a suite of software utilities for the 
> analysis of Mortgage and Asset Backed securities
> LazyLoad: yes
> License: GPL(>=3.0)
> Imports:  termstrc, 
>   lubridate, 
>   methods, 
>   optimx,
> Suggests: knitr,
>   devtools,
>   testthat
> VignetteBuilder: knitr
> 
> The Namespace is as follows:
> # Generated by roxygen2 (4.1.0): do not edit by hand
> 
> export(CPR.To.SMM)
> export(DollarRoll)
> export(Effective.Convexity)
> export(Effective.Duration)
> export(EstimYTM)
> export(MakeScenario)
> export(Mortgage.Monthly.Payment)
> export(MortgageCashFlow)
> export(PPC.Ramp)
> export(PassThroughAnalytics)
> export(PassThroughOAS)
> export(Rates)
> export(Remain.Balance)
> export(SMM.To.CPR)
> export(SMMVector.To.CPR)
> export(Sched.Prin)
> export(TermStructure)
> export(TimeValue)
> export(bondprice)
> import(methods)
> import(optimx)
> importFrom(lubridate,"%m+%")
> importFrom(termstrc,create_cashflows_matrix)
> importFrom(termstrc,create_maturities_matrix)
> importFrom(termstrc,estim_cs)
> importFrom(termstrc,estim_nss)
> importFrom(termstrc,forwardrates)
> importFrom(termstrc,spotrates)
> 
> 
> __
> R-help@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.

**
"The contents of this message do not reflect any position of the U.S. 
Government or NOAA."
**
Roy Mendelssohn
Supervisory Operations Research Analyst
NOAA/NMFS
Environmental Research Division
Southwest Fisheries Science Center
***Note new address and phone***
110 Shaffer Road
Santa Cruz, CA 95060
Phone: (831)-420-3666
Fax: (831) 420-3980
e-mail: roy.mendelss...@noaa.gov www: http://www.pfeg.noaa.gov/

"Old age and treachery will overcome youth and skill."
"From those who have been given much, much will be expected" 
"the arc of the moral universe is long, but it bends toward justice" -MLK Jr.

__
R-help@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.


[R] r script in web

2015-02-28 Thread hamid-reza kadkhodazadeh
hi
i want to run r script in web without install r on server(my server is
windows).
is it possible?how?

thank you

[[alternative HTML version deleted]]

__
R-help@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.


[R] Lubridate and NameSpace

2015-02-28 Thread Glenn Schultz

Hello All,

I am working on a package very near completion - roxygenizing it now.  The namespace 
imports from lubridate importFrom(lubridate,"%m+%").  The problem is:

Lubridate will not load with bondlab, I have to manually click on lubridate in 
R Studio to load it
I tried calling function using lubridate:::%m+% within my function based on 
some discussion I found online.  This is likely the correct idea but I don't 
think I am calling the function correctly since it does not work in the code 
when I use the above syntax.
Any suggestions are appreciated>

Best Glenn 

The description file is as follows: 

Package: BondLab
Type: Package
Title: A package for the analysis of structured products
Version: 0.0.0
Date: 2013-12-08
Author: Glenn Schultz, CFA
Maintainer: Glenn Schultz 
Description: The package provides a suite of software utilities for the 
analysis of Mortgage and Asset Backed securities
LazyLoad: yes
License: GPL(>=3.0)
Imports:  termstrc, 
          lubridate, 
          methods, 
          optimx,
Suggests: knitr,
          devtools,
          testthat
VignetteBuilder: knitr

The Namespace is as follows:
# Generated by roxygen2 (4.1.0): do not edit by hand

export(CPR.To.SMM)
export(DollarRoll)
export(Effective.Convexity)
export(Effective.Duration)
export(EstimYTM)
export(MakeScenario)
export(Mortgage.Monthly.Payment)
export(MortgageCashFlow)
export(PPC.Ramp)
export(PassThroughAnalytics)
export(PassThroughOAS)
export(Rates)
export(Remain.Balance)
export(SMM.To.CPR)
export(SMMVector.To.CPR)
export(Sched.Prin)
export(TermStructure)
export(TimeValue)
export(bondprice)
import(methods)
import(optimx)
importFrom(lubridate,"%m+%")
importFrom(termstrc,create_cashflows_matrix)
importFrom(termstrc,create_maturities_matrix)
importFrom(termstrc,estim_cs)
importFrom(termstrc,estim_nss)
importFrom(termstrc,forwardrates)
importFrom(termstrc,spotrates)


__
R-help@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.


[R] scatter plot matrix with multiple trend lines and p values

2015-02-28 Thread tianshu
I am trying to create a scatter plot matrix in which the lower panels
contain
scatter plots colored by group with trend lines by group, and the upper
panels contain r and p values. Using pairs() I was able to get close (ie,
scatter plot matrix on bottom with one trend line and correlation
coefficients and p values in the upper panel) but was unable to add two
lines. Using spm() I was able to get the multiple trend lines, but not the
upper
panel statistics. Does anyone know of a way to accomplish this?

My code using pairs:

pairs(~Sepal.Length+Sepal.Width+Petal.Length+Petal.Width, data = iris,
bg=c("red","blue","green")[iris$Species],
pch = 22,
lower.panel  =my_line <- function(x,y,...){
points(x,y,...)
abline(a = lm(y ~ x)$coefficients[1] , b = lm(y ~ x)$coefficients[2] ,
...)
},
upper.panel = panel.cor <- function(x, y, digits = 2, cex.cor, ...)
{
  usr <- par("usr"); on.exit(par(usr))
  par(usr = c(0, 1, 0, 1))
  # correlation coefficient
  r <- cor(x, y)
  txt <- format(c(r, 0.123456789), digits = digits)[1]
  txt <- paste("r= ", txt, sep = "")
  text(0.5, 0.6, txt)

  # p-value calculation
  p <- cor.test(x, y)$p.value
  txt2 <- format(c(p, 0.123456789), digits = digits)[1]
  txt2 <- paste("p= ", txt2, sep = "")
  if(p<0.01) txt2 <- paste("p= ", "<0.01", sep = "")
  text(0.5, 0.4, txt2)
})




--
View this message in context: 
http://r.789695.n4.nabble.com/scatter-plot-matrix-with-multiple-trend-lines-and-p-values-tp4703996.html
Sent from the R help mailing list archive at Nabble.com.
[[alternative HTML version deleted]]

__
R-help@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.


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 substrings).
  donttouch_regions <- reduce(do.call("c", lapply(donttouch_words, 
matchPattern, x0)))

  target_regions <- ranges(gaps(donttouch_regions))
  target_substrings <- extractAt(x0, target_regions)

  ## Modify them.
  old <- paste0(letters, collapse="")
  new <- paste0(LETTERS, collapse="")
  target_substrings <- chartr(old, new, target_substrings)

  ## Replace in original string.
  x1 <- replaceAt(x0, target_regions, target_substrings)

Then:

  > x1
57-letter "BString" instance
  seq: pmin(pmax(pmin(X1, X2), pmin(X3, X4)) == Y, pmax(Z1, Z1))

  > as.character(x1)
  [1] "pmin(pmax(pmin(X1, X2), pmin(X3, X4)) == Y, pmax(Z1, Z1))"

Hope this helps,
H.

On 02/27/2015 02:19 PM, Alrik Thiem wrote:

Dear R-help list,

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 lower-case letters that do not belong to
the functions "pmin" and "pmax" by 1 - toupper(...) to get

"pmin(pmax(pmin(1 - X1, X2), pmin(X3, X4)) == Y, pmax(Z1, 1 - Z1))"

Any ideas on how I could achieve that?

Many thanks and best wishes,

Alrik



Alrik Thiem
Post-Doctoral Researcher

Department of Philosophy
University of Geneva
Rue de Candolle 2
CH-1211 Geneva

+41 76 527 80 83

http://www.alrik-thiem.net
http://www.compasss.org

__
R-help@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.



--
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: hpa...@fredhutch.org
Phone:  (206) 667-5791
Fax:(206) 667-1319

__
R-help@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.


Re: [R] Firefox not showing R help.

2015-02-28 Thread Duncan Murdoch
On 28/02/2015 4:10 PM, Rolf Turner wrote:
> 
> Firefox recently updated itself on my laptop.  Now when I ask for R help 
> --- e.g. ?plot --- I just get my home page. And no help. If I do "?plot" 
> again after Firefox has opened its window, I just get yet another 
> Firefox window, opened to my home page.  (I have my preferences set to
> 
>  "When Firefox starts Show my homepage"
> 
> --- as I always have had in the past.)

I would guess that browseURL() won't work for any URL.  Is that right?

What does getOption("browser") give you in R?  If it is just a character
string (e.g. "xdg-open" is what I get in Ubuntu), does it work from your
command line, outside of R, e.g. for me that test would be

xdg-open http://www.r-project.org

If that doesn't work, but you can figure out a command line way to open
a particular URL, change getOption("browser") to use that.

Duncan Murdoch

> 
> The Firefox that I am currently running is (according Firefox help
> --> "About Firefox") is version 36.0.
> 
> Can anyone suggest to me how I can get my html R help back?
> 
> For what it's worth:  I am using Linux, Fedora 17.  (Yes, I know it's 
> elderly, but then so am I. :-) )
> 
> Also in case it has any relevance:
> 
>>> sessionInfo()
>> R version 3.1.2 (2014-10-31)
>> Platform: x86_64-unknown-linux-gnu (64-bit)
>>
>> locale:
>>  [1] LC_CTYPE=en_NZ.utf8   LC_NUMERIC=C
>>  [3] LC_TIME=en_NZ.utf8LC_COLLATE=en_NZ.utf8
>>  [5] LC_MONETARY=en_NZ.utf8LC_MESSAGES=en_NZ.utf8
>>  [7] LC_PAPER=en_NZ.utf8   LC_NAME=C
>>  [9] LC_ADDRESS=C  LC_TELEPHONE=C
>> [11] LC_MEASUREMENT=en_NZ.utf8 LC_IDENTIFICATION=C
>>
>> attached base packages:
>> [1] stats graphics  grDevices utils datasets  methods   base
>>
>> other attached packages:
>> [1] spatstat_1.40-0.064 misc_0.0-16
>>
>> loaded via a namespace (and not attached):
>>  [1] abind_1.4-0 deldir_0.1-7goftest_1.0-2   grid_3.1.2
>>  [5] lattice_0.20-29 Matrix_1.1-4mgcv_1.8-3  nlme_3.1-118
>>  [9] polyclip_1.3-1  tensor_1.5  tools_3.1.2
> 
> cheers,
> 
> Rolf Turner
>

__
R-help@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.


[R] Firefox not showing R help.

2015-02-28 Thread Rolf Turner


Firefox recently updated itself on my laptop.  Now when I ask for R help 
--- e.g. ?plot --- I just get my home page. And no help. If I do "?plot" 
again after Firefox has opened its window, I just get yet another 
Firefox window, opened to my home page.  (I have my preferences set to


"When Firefox starts Show my homepage"

--- as I always have had in the past.)

The Firefox that I am currently running is (according Firefox help
--> "About Firefox") is version 36.0.

Can anyone suggest to me how I can get my html R help back?

For what it's worth:  I am using Linux, Fedora 17.  (Yes, I know it's 
elderly, but then so am I. :-) )


Also in case it has any relevance:


sessionInfo()

R version 3.1.2 (2014-10-31)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_NZ.utf8   LC_NUMERIC=C
 [3] LC_TIME=en_NZ.utf8LC_COLLATE=en_NZ.utf8
 [5] LC_MONETARY=en_NZ.utf8LC_MESSAGES=en_NZ.utf8
 [7] LC_PAPER=en_NZ.utf8   LC_NAME=C
 [9] LC_ADDRESS=C  LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_NZ.utf8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

other attached packages:
[1] spatstat_1.40-0.064 misc_0.0-16

loaded via a namespace (and not attached):
 [1] abind_1.4-0 deldir_0.1-7goftest_1.0-2   grid_3.1.2
 [5] lattice_0.20-29 Matrix_1.1-4mgcv_1.8-3  nlme_3.1-118
 [9] polyclip_1.3-1  tensor_1.5  tools_3.1.2


cheers,

Rolf Turner

--
Rolf Turner
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276
Home phone: +64-9-480-4619

__
R-help@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.


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

Replace the + (i.e. 1 or more) in the pattern with a * (i.e. 0 or more):

   x <- "pmin(pmax(pmin(a,B),pmin(a,C,d))==Y,pmax(E,e))"

   gsub("(\\b[a-oq-z][a-z0-9]*)", "1-\\U\\1", x, perl = TRUE)

giving:

   [1] "pmin(pmax(pmin(1-A,B),pmin(1-A,C,1-D))==Y,pmax(E,1-E))"

Here is a visualization of the regular expression:

   https://www.debuggex.com/i/5ByOCQS2zIdPEf-f.png


On Sat, Feb 28, 2015 at 8:16 AM, Alrik Thiem  wrote:
> Dear Gabor,
>
> Many thanks. Works like a charm, but I can't get it to work with
>
> "pmin(pmax(pmin(a,B),pmin(a,C,d))==Y,pmax(E,e))"
>
> i.e., with strings where there're no integers following the components in the 
> pmin/pmax functions. Could this be generalized to handle both cases?
>
> 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  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 lower-case letters that do not belong to
>> the functions "pmin" and "pmax" by 1 - toupper(...) to get
>>
>> "pmin(pmax(pmin(1 - X1, X2), pmin(X3, X4)) == Y, pmax(Z1, 1 - Z1))"
>>
>
> Assuming x is the input string:
>
> gsub("(\\b[a-oq-z][a-z0-9]+)", "1-\\U\\1", x, perl = TRUE)
> ## [1] "pmin(pmax(pmin(1-X1, X2), pmin(X3, X4)) == Y, pmax(Z1, 1-Z1))"
>
>
>
> --
> Statistics & Software Consulting
> GKX Group, GKX Associates Inc.
> tel: 1-877-GKX-GROUP
> email: ggrothendieck at gmail.com
>



-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

__
R-help@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.

Re: [R] Substring replacement in string

2015-02-28 Thread Gabor Grothendieck
Replace the + (i.e. 1 or more) in the pattern with a * (i.e. 0 or more):

   x <- "pmin(pmax(pmin(a,B),pmin(a,C,d))==Y,pmax(E,e))"

   gsub("(\\b[a-oq-z][a-z0-9]*)", "1-\\U\\1", x, perl = TRUE)

giving:

   [1] "pmin(pmax(pmin(1-A,B),pmin(1-A,C,1-D))==Y,pmax(E,1-E))"

Here is a visualization of the regular expression:

   https://www.debuggex.com/i/5ByOCQS2zIdPEf-f.png


On Sat, Feb 28, 2015 at 8:16 AM, Alrik Thiem  wrote:
> Dear Gabor,
>
> Many thanks. Works like a charm, but I can't get it to work with
>
> "pmin(pmax(pmin(a,B),pmin(a,C,d))==Y,pmax(E,e))"
>
> i.e., with strings where there're no integers following the components in the 
> pmin/pmax functions. Could this be generalized to handle both cases?
>
> 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  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 lower-case letters that do not belong to
>> the functions "pmin" and "pmax" by 1 - toupper(...) to get
>>
>> "pmin(pmax(pmin(1 - X1, X2), pmin(X3, X4)) == Y, pmax(Z1, 1 - Z1))"
>>
>
> Assuming x is the input string:
>
> gsub("(\\b[a-oq-z][a-z0-9]+)", "1-\\U\\1", x, perl = TRUE)
> ## [1] "pmin(pmax(pmin(1-X1, X2), pmin(X3, X4)) == Y, pmax(Z1, 1-Z1))"
>
>
>
> --
> Statistics & Software Consulting
> GKX Group, GKX Associates Inc.
> tel: 1-877-GKX-GROUP
> email: ggrothendieck at gmail.com
>



-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

__
R-help@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.

Re: [R] evaluate logical expressions

2015-02-28 Thread JS Huang
Hi,

  I assume input y to wrapper <- function(y) {function(x) {(y)}} is a
function.  In the statement to assign gfunc[[i]]<-
gsub("(Gene)([[:digit:]])", "x[\\2]", func[[i]]) the mode of
gsub("(Gene)([[:digit:]])", "x[\\2]", func[[i]]) is character.  Is this the
issue?



--
View this message in context: 
http://r.789695.n4.nabble.com/evaluate-logical-expressions-tp4703964p4703970.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Substring replacement in string

2015-02-28 Thread Alrik Thiem
Ah, I see what you mean. Thanks for suggesting. I'll try.

-Ursprüngliche Nachricht-
Von: Michael Dewey [mailto:i...@aghmed.fsnet.co.uk] 
Gesendet: Samstag, 28. Februar 2015 17:31
An: Alrik Thiem
Cc: r-help@r-project.org
Betreff: Re: AW: [R] Substring replacement in string

Your original problem statement seemed to me to be one of wanting to 
transform all the lower case identifiers to upper except for pmin and 
pmax. My suggestion was not to bother and transform everything and then 
define PMIN and PMAX.

On 28/02/2015 14:34, Alrik Thiem wrote:
> Dear Michael
>
> I'm not sure how you mean this. Maybe a more general description of my 
> problem is helpful for clarifying.
>
> What I have to deal with are truth table output functions that always take, 
> for example, the following form:
>
> Delta <- "(a*B+a*C*d<=>Y)*(E+e)"
>
> I.e. these functions will always have the structure (.*.+.*.+...<=>.)*(.+.), 
> where the dots in the antecedent could be further conjunctions of unspecified 
> complexity. I now need to filter all rows from the truth table that are 
> compatible with this output function. To create the input part of the truth 
> table "tt" for Delta above, I do:
>
> library(QCA) # createMatrix() function is part of this package
> Delta.upper <- toupper(Delta)
> f.names <- unique(unlist(strsplit(Delta.upper, "[(*+<=>)]")))
> f.names <- f.names[f.names != ""]
> tt <- data.frame(createMatrix(rep(2, length(f.names
> dimnames(tt) <- list(as.character(seq(2^length(f.names))), f.names)
> tt
>
>> tt
> A B C D Y E
> 1  0 0 0 0 0 0
> 2  0 0 0 0 0 1
> .  . . . . . .
> 63 1 1 1 1 1 0
> 64 1 1 1 1 1 1
>
> I now need to transform Delta into a string of the following form in order to 
> extract the subset of compatible rows from "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"
>
> With this 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-
> 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 suggestion but why not just define new functions
> PMIN and PMAX to call pmin and pmax. Obviously that does not solve your
> problem if it is more general than your example.
>
> On 28/02/2015 13:16, Alrik Thiem wrote:
>> Dear Gabor,
>>
>> Many thanks. Works like a charm, but I can't get it to work with
>>
>> "pmin(pmax(pmin(a,B),pmin(a,C,d))==Y,pmax(E,e))"
>>
>> i.e., with strings where there're no integers following the components in 
>> the pmin/pmax functions. Could this be generalized to handle both cases?
>>
>> 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  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 lower-case letters that do not belong to
>>> the functions "pmin" and "pmax" by 1 - toupper(...) to get
>>>
>>> "pmin(pmax(pmin(1 - X1, X2), pmin(X3, X4)) == Y, pmax(Z1, 1 - Z1))"
>
>>>
>>
>> Assuming x is the input string:
>>
>> gsub("(\\b[a-oq-z][a-z0-9]+)", "1-\\U\\1", x, perl = TRUE)
>> ## [1] "pmin(pmax(pmin(1-X1, X2), pmin(X3, X4)) == Y, pmax(Z1, 1-Z1))"
>>
>>
>>
>

-- 
Michael
http://www.dewey.myzen.co.uk

__
R-help@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.

Re: [R] Substring replacement in string

2015-02-28 Thread Michael Dewey
Your original problem statement seemed to me to be one of wanting to 
transform all the lower case identifiers to upper except for pmin and 
pmax. My suggestion was not to bother and transform everything and then 
define PMIN and PMAX.


On 28/02/2015 14:34, Alrik Thiem wrote:

Dear Michael

I'm not sure how you mean this. Maybe a more general description of my problem 
is helpful for clarifying.

What I have to deal with are truth table output functions that always take, for 
example, the following form:

Delta <- "(a*B+a*C*d<=>Y)*(E+e)"

I.e. these functions will always have the structure (.*.+.*.+...<=>.)*(.+.), where the 
dots in the antecedent could be further conjunctions of unspecified complexity. I now need to 
filter all rows from the truth table that are compatible with this output function. To create 
the input part of the truth table "tt" for Delta above, I do:

library(QCA) # createMatrix() function is part of this package
Delta.upper <- toupper(Delta)
f.names <- unique(unlist(strsplit(Delta.upper, "[(*+<=>)]")))
f.names <- f.names[f.names != ""]
tt <- data.frame(createMatrix(rep(2, length(f.names
dimnames(tt) <- list(as.character(seq(2^length(f.names))), f.names)
tt


tt

A B C D Y E
1  0 0 0 0 0 0
2  0 0 0 0 0 1
.  . . . . . .
63 1 1 1 1 1 0
64 1 1 1 1 1 1

I now need to transform Delta into a string of the following form in order to extract the 
subset of compatible rows from "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"

With this 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-
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 suggestion but why not just define new functions
PMIN and PMAX to call pmin and pmax. Obviously that does not solve your
problem if it is more general than your example.

On 28/02/2015 13:16, Alrik Thiem wrote:

Dear Gabor,

Many thanks. Works like a charm, but I can't get it to work with

"pmin(pmax(pmin(a,B),pmin(a,C,d))==Y,pmax(E,e))"

i.e., with strings where there're no integers following the components in the 
pmin/pmax functions. Could this be generalized to handle both cases?

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  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 lower-case letters that do not belong to
the functions "pmin" and "pmax" by 1 - toupper(...) to get

"pmin(pmax(pmin(1 - X1, X2), pmin(X3, X4)) == Y, pmax(Z1, 1 - Z1))"






Assuming x is the input string:

gsub("(\\b[a-oq-z][a-z0-9]+)", "1-\\U\\1", x, perl = TRUE)
## [1] "pmin(pmax(pmin(1-X1, X2), pmin(X3, X4)) == Y, pmax(Z1, 1-Z1))"







--
Michael
http://www.dewey.myzen.co.uk

__
R-help@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.

Re: [R] title of r plots

2015-02-28 Thread William Dunlap
Use help("plotmath") to see all the details - you can use tildes for spaces,
asterisks for no spaces.

Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Fri, Feb 27, 2015 at 8:52 PM, li li  wrote:

>
> Thanks very much.
> Also How do add an empty space when using expression()?
> When I do the following, it returns an error message.
>
>
> plot(1,1,main=expression(-70*degree*C%+-%10*degree*C/Ambient Condition))
>
>
>
>Hanna
>
>
> 2015-02-27 23:03 GMT-05:00 William Dunlap :
>
>>  plot(1,1,main=expression(-70*degree*C%+-%10*degree*C/Ambient))
>>
>>  Bill Dunlap
>> TIBCO Software
>> wdunlap tibco.com
>>
>>  On Fri, Feb 27, 2015 at 7:27 PM, li li  wrote:
>>
>>>   Hi all,
>>>   I would like to add "-70°C ± 10°C/Ambient"  as the title of my plot.
>>> Could anyone give some help on this?
>>>   Thanks.
>>>Hanna
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> __
>>> R-help@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.
>>
>>
>>
>

[[alternative HTML version deleted]]

__
R-help@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.

Re: [R] Substring replacement in string

2015-02-28 Thread William Dunlap
  string <- "pmin(1, x)"
  expr <- parse(text=string)[[1]]

will convert the string to an unevaluated language object.

Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Fri, Feb 27, 2015 at 11:25 PM, Alrik Thiem  wrote:

> Many thanks. Unfortunately, I cannot work directly on these expressions
> since they’re only created from other strings. Would I first have to
> transform these strings to unevaluated expressions?
>
>
>
> *Von:* William Dunlap [mailto:wdun...@tibco.com]
> *Gesendet**:* Freitag, 27. Februar 2015 23:39
> *An:* Alrik 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(expr), c("pmin", "pmax"))
>
> toReplace <- grep(value = TRUE, "[a-z]", toReplace)
>
> names(toReplace) <- toReplace
>
> replacementList <- lapply(toReplace, function(name) call("-",
>
> 1, as.name(toupper(name
>
> do.call(substitute, list(expr, replacementList))
>
> }
>
>
>
> > In <- quote(pmin(pmax(pmin(x1, X2), pmin(X3, X4)) == Y, pmax(Z1, z1)))
>
> > Desired <- quote(pmin(pmax(pmin(1 - X1, X2), pmin(X3, X4)) == Y,
> pmax(Z1, 1 - Z1)))
>
> > all.equal(Desired, f(In))
>
> [1] TRUE
>
>
>
>
>
>
>
>
>
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
>
>
> On Fri, Feb 27, 2015 at 2:19 PM, Alrik Thiem 
> wrote:
>
> Dear R-help list,
>
> 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 lower-case letters that do not belong to
> the functions "pmin" and "pmax" by 1 - toupper(...) to get
>
> "pmin(pmax(pmin(1 - X1, X2), pmin(X3, X4)) == Y, pmax(Z1, 1 - Z1))"
>
> Any ideas on how I could achieve that?
>
> Many thanks and best wishes,
>
> Alrik
>
>
> 
> Alrik Thiem
> Post-Doctoral Researcher
>
> Department of Philosophy
> University of Geneva
> Rue de Candolle 2
> CH-1211 Geneva
>
> +41 76 527 80 83
>
> http://www.alrik-thiem.net
> http://www.compasss.org
>
> __
> R-help@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.
>
>
>

[[alternative HTML version deleted]]

__
R-help@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.

Re: [R] Substring replacement in string

2015-02-28 Thread Alrik Thiem
Dear Michael

I'm not sure how you mean this. Maybe a more general description of my problem 
is helpful for clarifying.

What I have to deal with are truth table output functions that always take, for 
example, the following form:

Delta <- "(a*B+a*C*d<=>Y)*(E+e)"

I.e. these functions will always have the structure (.*.+.*.+...<=>.)*(.+.), 
where the dots in the antecedent could be further conjunctions of unspecified 
complexity. I now need to filter all rows from the truth table that are 
compatible with this output function. To create the input part of the truth 
table "tt" for Delta above, I do:

library(QCA) # createMatrix() function is part of this package
Delta.upper <- toupper(Delta)
f.names <- unique(unlist(strsplit(Delta.upper, "[(*+<=>)]")))
f.names <- f.names[f.names != ""]
tt <- data.frame(createMatrix(rep(2, length(f.names
dimnames(tt) <- list(as.character(seq(2^length(f.names))), f.names)
tt

> tt
   A B C D Y E
1  0 0 0 0 0 0
2  0 0 0 0 0 1
.  . . . . . .
63 1 1 1 1 1 0
64 1 1 1 1 1 1

I now need to transform Delta into a string of the following form in order to 
extract the subset of compatible rows from "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"

With this 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-
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 suggestion but why not just define new functions 
PMIN and PMAX to call pmin and pmax. Obviously that does not solve your 
problem if it is more general than your example.

On 28/02/2015 13:16, Alrik Thiem wrote:
> Dear Gabor,
>
> Many thanks. Works like a charm, but I can't get it to work with
>
> "pmin(pmax(pmin(a,B),pmin(a,C,d))==Y,pmax(E,e))"
>
> i.e., with strings where there're no integers following the components in the 
> pmin/pmax functions. Could this be generalized to handle both cases?
>
> 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  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 lower-case letters that do not belong to
>> the functions "pmin" and "pmax" by 1 - toupper(...) to get
>>
>> "pmin(pmax(pmin(1 - X1, X2), pmin(X3, X4)) == Y, pmax(Z1, 1 - Z1))"
>>
>
> Assuming x is the input string:
>
> gsub("(\\b[a-oq-z][a-z0-9]+)", "1-\\U\\1", x, perl = TRUE)
> ## [1] "pmin(pmax(pmin(1-X1, X2), pmin(X3, X4)) == Y, pmax(Z1, 1-Z1))"
>
>
>

-- 
Michael
http://www.dewey.myzen.co.uk

__
R-help@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.

Re: [R] Substring replacement in string

2015-02-28 Thread Michael Dewey

Dear Alrik

This may seem a silly suggestion but why not just define new functions 
PMIN and PMAX to call pmin and pmax. Obviously that does not solve your 
problem if it is more general than your example.


On 28/02/2015 13:16, Alrik Thiem wrote:

Dear Gabor,

Many thanks. Works like a charm, but I can't get it to work with

"pmin(pmax(pmin(a,B),pmin(a,C,d))==Y,pmax(E,e))"

i.e., with strings where there're no integers following the components in the 
pmin/pmax functions. Could this be generalized to handle both cases?

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  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 lower-case letters that do not belong to
the functions "pmin" and "pmax" by 1 - toupper(...) to get

"pmin(pmax(pmin(1 - X1, X2), pmin(X3, X4)) == Y, pmax(Z1, 1 - Z1))"



Assuming x is the input string:

gsub("(\\b[a-oq-z][a-z0-9]+)", "1-\\U\\1", x, perl = TRUE)
## [1] "pmin(pmax(pmin(1-X1, X2), pmin(X3, X4)) == Y, pmax(Z1, 1-Z1))"





--
Michael
http://www.dewey.myzen.co.uk

__
R-help@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.

[R] Using a text file as a removeWord dictionary in tm_map

2015-02-28 Thread Sun Shine

Hi list

Although this query applies specifically to the tm package, perhaps it's 
something that others might be able to lend a thought to.


Using tm to do some initial text mining, I want to include an external 
(to R) generated dictionary of words that I want removed from the corpus.


I have created a comma separated list of terms in " " marks in a 
stopList.txt plain UTF-8 file. I want to read this into R, so do:


> stopDict <- read.table('~/path/to/file/stopList.txt', sep=',')

When I want to load it as part of the removeWords function in tm, I do:

> docs <- tm_map(docs, removeWords, stopDict)

which has no effect. Neither does:

> docs <- tm_map(docs, removeWords, c(stopDict))

What am I not seeing/ doing?

How do I pass a text file with pre-defined terms to the removeWords 
transform of tm?


Thanks for any ideas.

Cheers

Sun

__
R-help@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.


Re: [R] Substring replacement in string

2015-02-28 Thread Alrik Thiem
Dear Gabor,

Many thanks. Works like a charm, but I can't get it to work with

"pmin(pmax(pmin(a,B),pmin(a,C,d))==Y,pmax(E,e))"

i.e., with strings where there're no integers following the components in the 
pmin/pmax functions. Could this be generalized to handle both cases?

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  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 lower-case letters that do not belong to
> the functions "pmin" and "pmax" by 1 - toupper(...) to get
>
> "pmin(pmax(pmin(1 - X1, X2), pmin(X3, X4)) == Y, pmax(Z1, 1 - Z1))"
>

Assuming x is the input string:

gsub("(\\b[a-oq-z][a-z0-9]+)", "1-\\U\\1", x, perl = TRUE)
## [1] "pmin(pmax(pmin(1-X1, X2), pmin(X3, X4)) == Y, pmax(Z1, 1-Z1))"



-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

__
R-help@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.

[R] Package survMisc

2015-02-28 Thread Endy BlackEndy
Hi R users. I have some problems with the package “survMisc”. When I am
loading it I am getting the following



> library(survMisc)

Loading required package: survival

Loading required package: splines

Loading required package: km.ci

Loading required package: ggplot2

Loading required package: data.table

data.table 1.9.4  For help type: ?data.table

*** NB: by=.EACHI is now explicit. See README to restore previous behaviour.

Loading required package: gridExtra

Loading required package: grid

Loading required package: rpart



Attaching package: ‘survMisc’



The following objects are masked from ‘package:stats’:



AIC, BIC, median, quantile



   In the above output I noticed the line with the three stars (*). In
order to restore the data.table in its previous behavior I tried to locate
the README file but I couldn’t.

   I ignored that NB in the previous output and I continue to run the
example given in the above mentioned package for the routine comp(). The
commands and the output are given below.

> ### 2 curves

> data(kidney,package="KMsurv")

> s1 <- survfit(Surv(time=time, event=delta) ~ type, data=kidney )

> comp(s1)

$tne

   t  n  e   n_type=1   e_type=1   n_type=2   e_type=2

 1:  1.586 2   431
431

 2:  3.580 2   401
401

 3:  4.572 4   362
362

 4:  5.566 2   331
331

 5:  8.560 4   302  30
   2

 6:  9.554 2   271
271

 7: 10.5   50 2   251
251

 8: 11.544 2   22   1
221

 9: 15.528 4   14   2
142

10: 16.5   26 2   13   1
131

11: 18.5   22 2   11   1
  111

12: 23.5 8 24 1
41

13: 26.5 6 23 1
31



$tests

$tests$lrTests

ChiSq df p

Log-rank0  1 1

Gehan-Breslow (mod~ Wilcoxon) 0  1 1

Tarone-Ware  0  1 1

Peto-Peto  0  1 1

Mod~ Peto-Peto (Andersen)0  1 1

Flem~-Harr~ with p=1, q=1  0  1 1



$tests$supTests

 Q p

Log-rank 0 1

Gehan-Breslow (mod~ Wilcoxon)  0 1

Tarone-Ware   0 1

Peto-Peto   0 1

Mod~ Peto-Peto (Andersen) 0 1

Renyi Flem~-Harr~ with p=1, q=1 0 1



Notice the zeros (0) that corresponds to the test statistics. (To my
opinion those zeros are strongly related to the NB above).

   Next I noticed the following strange, to my opinion, thing.  More
precisely I have written the following
routine


proc<-function(){

 rm(list=ls())

 library(survMisc)

 d<-read.table("C:\\Program
Files\\R\\Data\\Survival\\HosmLem.txt",fill=TRUE,header=TRUE)

 d4<-as.factor(d[,4])

 s<-survfit(Surv(d[,2], d[,5])~d4)

 ctest<-comp(s)$tests

 print(ctest)

}

The data used are those of Hosmer and Lemeshow book on Applied Survival
Analysis. The first rows of this data set follow.

id Time Age Drug Censorentdateenddate

  15  460  1   05/15/1990 10/14/1990

  26  351  0   09/19/1989 03/20/1990

  38  301  1   04/21/1991 12/20/1991

  43  301  1   01/03/1991 04/04/1991

  5   22  360  1   09/18/1989 07/19/1991

  61  321  003/18/1991 04/17/1991

When I run the function proc() I am getting the answer

> proc()

Error in Surv(d[, 2], d[, 5]) : object 'd' not found

In contrast when I run the same routine command-by-command I am getting the
following output

$lrTests

 ChiSq df p

Log-rank 0  1 1

Gehan-Breslow (mod~ Wilcoxon)  0  1 1

Tarone-Ware   0  1 1

Peto-Peto   0  1 1

Mod~ Peto-Peto (Andersen) 0  1 1

Flem~-Harr~ with p=1, q=1   0  1 1



$supTests

  Q p

Log-rank  0 1

Gehan-Breslow (mod~ Wilcoxon)   0 1

Tarone-Ware0 1

Peto-Peto0 1

Mod~ Peto-Peto (Andersen)   

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 lower-case letters that do not belong to
> the functions "pmin" and "pmax" by 1 - toupper(...) to get
>
> "pmin(pmax(pmin(1 - X1, X2), pmin(X3, X4)) == Y, pmax(Z1, 1 - Z1))"
>

Assuming x is the input string:

gsub("(\\b[a-oq-z][a-z0-9]+)", "1-\\U\\1", x, perl = TRUE)
## [1] "pmin(pmax(pmin(1-X1, X2), pmin(X3, X4)) == Y, pmax(Z1, 1-Z1))"



-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

__
R-help@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.