[Bioc-devel] A quick questions on writing R functions
Li, Dongmei
Dongmei_Li at URMC.Rochester.edu
Fri Feb 20 15:41:14 CET 2015
Thanks so much for your comments and help!
Best,
Dongmei
From: Gabe Becker [mailto:becker.gabe at gene.com]
Sent: Friday, February 20, 2015 9:33 AM
To: Li, Dongmei
Cc: bioc-devel at r-project.org
Subject: Re: [Bioc-devel] A quick questions on writing R functions
Dongmei,
This isn't really the right list for this type of question. That said, I can give you a few pointers.
The actual section of the manual you quoted is about documenting your function, not the code of the function itself.
That said, "eval" is not a good name for your function. It doesn't tell the caller what the function is going to do, and it will mask the eval function in base (this is unlikely to actually cause any problems, but it's bad practice).
This function could also be vectorized if you turn it into a an elementwise comparsion of two matrices followed by a call to colSums. Even if not, I suspect that reptition is simply the length of the vectors you pass in? If so, just call mean on the logical vectors, no need to add them and divide as a separate step (though admittedly that isn't really going to save you much).
~G
On Fri, Feb 20, 2015 at 6:10 AM, Li, Dongmei <Dongmei_Li at urmc.rochester.edu<mailto:Dongmei_Li at urmc.rochester.edu>> wrote:
Hi,
I'm developing an R package and got the following suggestions for revising the functions:
"When a function returns a named list, a good practise is to start the
\value section with the following:
A named list with the following components:
and then to itemize the components"
This is an example of my current function:
eval<-
function (ord_vec_t, ord_vec_pvalue, eval_matrix_t, eval_matrix_pvalue, repetition)
{
rowsdim <- length(ord_vec_t)
p_pvalue <- rep(NA, rowsdim)
p_tstat <- rep(NA, rowsdim)
for (g in 1:rowsdim) {
p_pvalue[g] <- sum(eval_matrix_pvalue[g, ] <= ord_vec_pvalue[g])/repetition
p_tstat[g] <- sum(abs(eval_matrix_t[g, ]) >= abs(ord_vec_t[g]))/repetition
}
mylist <- list(p_pvalue = p_pvalue, p_tstat = p_tstat)
return(mylist)
}
Anyone could offer some suggestions on revising the function based on the comments? Thanks so much for all your help!
Best,
Dongmei
_______________________________________________
Bioc-devel at r-project.org<mailto:Bioc-devel at r-project.org> mailing list
https://stat.ethz.ch/mailman/listinfo/bioc-devel<https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_bioc-2Ddevel&d=AwMFaQ&c=4sF48jRmVAe_CH-k9mXYXEGfSnM3bY53YSKuLUQRxhA&r=azjhQW59umxfk67jsIXeg7AS2ugqKLkykGYJFRwaLto&m=qqsvuTQftkkIrTwQWWynG_Y_UWBGtmC2pUjlk0C4Tss&s=I1Rjmnpu9a8_u14tWmTe-mwgwqTItRQOpIy_9uork8Y&e=>
--
Gabriel Becker, Ph.D
Computational Biologist
Genentech Research
[[alternative HTML version deleted]]
More information about the Bioc-devel
mailing list