[Bioc-devel] A quick questions on writing R functions
Gabe Becker
becker.gabe at gene.com
Fri Feb 20 15:33:20 CET 2015
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>
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 mailing list
> https://stat.ethz.ch/mailman/listinfo/bioc-devel
>
--
Gabriel Becker, Ph.D
Computational Biologist
Genentech Research
[[alternative HTML version deleted]]
More information about the Bioc-devel
mailing list