Hi Bert, Thank you, yes, you are right. I want to consolidate the three functions into one functions by adding more arguments, adding flexibility to accommodate the number of clusters or the number of Kaplan Meier curves generated in one figure. So, I just need to define one function. Thanks, Ding From: Bert Gunter [mailto:bgunter.4567 at gmail.com] Sent: Sunday, January 14, 2018 9:50 AM To: Ding, Yuan Chun <ycding at coh.org> Subject: Re: [R] consolidate three function into one I have not looked at your code *at all*, so I am not sure what exactly you mean by "consolidate." Is this what you are after? f1 <- function(...) { code 1} f2 <- function(...) { code 2} f3 <- function(...) { code 3} ## can be "consolidated as": f <- function( someargs, ...){ if( expr(someargs)) f1(...) else if(expr2(someargs)) f2(...) else f3(...) } The "..." argument to f can soak up any named additional arguments you wish to pass to f1, f2, or f3. My apologies if this is offbase or too vague, and feel free to ignore in that case. I don't have the patience to go trough your code in detail. Others may and give you what you want. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Sun, Jan 14, 2018 at 9:17 AM, Ding, Yuan Chun <ycding at coh.org<mailto:ycding at coh.org>> wrote: HI R users, I construct dendrogram tree and cut the tree into different clusters, then generate survival curves by the following three functions. All variables are included in an inputfile. Can you help me to consolidate the following three function into one functions? I thought about using if else function, but not sure how to do it. Thank you, Ding # function to generate RFS RFS2cluster <- function( inputfile ) { cluster2<- survfit(Surv(RFS_days, OV_Had_a_Recurrence_CODE) ~ clusters, data = inputfile) ggsurvplot(cluster2, data = inputfile, risk.table = F, palette = c("red", "black"), ylim=c(0,1), ggtheme = theme_bw(), xlab="Relapse Free Suvival (Days)", main = "Survival curve", pval = TRUE, font.x = 16, font.y = 16, font.tickslab = 14, font.legend =c(14,"plain","black"), legend = "bottom", legend.title = "Tree Cluster", legend.labs = c("Cluster1", "Cluster2"), lty=1, lwd=3) } RFS3cluster <- function( inputfile ) { cluster3<- survfit(Surv(RFS_days, OV_Had_a_Recurrence_CODE) ~ clusters, data = inputfile) ggsurvplot(cluster3, data = inputfile, risk.table = F, palette = c("red", "black", "green"), ylim=c(0,1), ggtheme = theme_bw(), xlab="Relapse Free Suvival (Days)", main = "Survival curve", pval = TRUE, font.x = 16, font.y = 16, font.tickslab = 14, font.legend =c(14,"plain","black"), legend = "bottom", legend.title = "Tree Cluster", legend.labs = c("Cluster1", "Cluster2", "Cluster3"), lty=1, lwd=3) } RFS4cluster <- function( inputfile ) { cluster4<- survfit(Surv(RFS_days, OV_Had_a_Recurrence_CODE) ~ clusters, data = inputfile) ggsurvplot(cluster4, data = inputfile, risk.table = F, palette = c("red", "black", "green", "blue"), ylim=c(0,1), ggtheme = theme_bw(), xlab="Relapse Free Suvival (Days)", main = "Survival curve", pval = TRUE, font.x = 16, font.y = 16, font.tickslab = 14, font.legend =c(14,"plain","black"), legend = "bottom", legend.title = "Tree Cluster", legend.labs = c("Cluster1", "Cluster2", "Cluster3", "Cluster4"), lty=1, lwd=3) } -----Original Message----- From: R-help [mailto:r-help-bounces at r-project.org<mailto:r-help-bounces at r-project.org>] On Behalf Of imane hajar Sent: Friday, January 12, 2018 7:42 AM To: r-help at r-project.org<mailto:r-help at r-project.org> Subject: [R] Help with packages (methods, stats, stats4) [Attention: This email came from an external source. Do not open attachments or click on links from unknown senders or unexpected emails.] hello, Can you please give me a hand with this problem,well i can't install these packages: - stats - methods - stats4 when i tried the following command : *library(help = "stats") * , it gave me this output (*see picture*), so i contacted the Maintainer of the package at (*R-core at r-project.org<mailto:R-core at r-project.org> <R-core at r-project.org<mailto:R-core at r-project.org>>*) but he said that i write to the wrong place. (i want to install those packages in order to use the "DVstats" package) (i have the latest version of R (3.4.3 ) and Rstudio(1.2.240) ) thank you Regards --------------------------------------------------------------------- -SECURITY/CONFIDENTIALITY WARNING- This message (and any attachments) are intended solely for the individual or entity to which they are addressed. This communication may contain information that is privileged, confidential, or exempt from disclosure under applicable law (e.g., personal health information, research data, financial information). Because this e-mail has been sent without encryption, individuals other than the intended recipient may be able to view the information, forward it to others or tamper with the information without the knowledge or consent of the sender. If you are not the intended recipient, or the employee or person responsible for delivering the message to the intended recipient, any dissemination, distribution or copying of the communication is strictly prohibited. If you received the communication in error, please notify the sender immediately by replying to this message and deleting the message and any accompanying files from your system. If, due to the security risks, you do not wish to r eceive further communications via e-mail, please reply to this message and inform the sender that you do not wish to receive further e-mail from the sender. (LCP301) --------------------------------------------------------------------- ______________________________________________ R-help at r-project.org<mailto: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. [[alternative HTML version deleted]]