[R] Writing R package and do.call

Gabor Grothendieck ggrothendieck at gmail.com
Tue Mar 3 03:52:45 CET 2009


Try this:

temp.fn.2 <- function(mean = 0, sd = 1, n = 101) {
   x <- seq(mean - sd, mean + sd, length = n)
   plot(x, dnorm(x), type = "l")
}

# test
temp.fn.2()

On Mon, Mar 2, 2009 at 8:46 PM, Rob Foxall <rfoxall27 at gmail.com> wrote:
> Dear R-Help,
>
> I have written a function, which in simplified format can be represented as:
>
> temp.fn <- function(my.mean,my.sd){
>   Parameters <- list(mean = my.mean, sd = my.sd)
>   curve(do.call(dnorm,c(list(x), Parameters)), from = my.mean-my.sd,
> to = my.mean+my.sd)
> }
>
> This works as I want it do. Wishing to immortalise this function into
> my very own package however, results in the following warning:
> (Running R CMD check myPackage)
>
> * checking R code for possible problems ... NOTE
> temp.fn: no visible binding for global variable 'x'
>
> Although it doesn't seem to matter, I would feel more comfortable if
> there was an alternative way which avoided this warning.
> ( I can avoid the warning, by pointlessly defining x, e.g. "x <- 1",
> but this seems pretty ugly!)
>
> Cheers,
> Rob.
>
>> version
>               _
> platform       i386-pc-mingw32
> arch           i386
> os             mingw32
> system         i386, mingw32
> status
> major          2
> minor          8.1
> year           2008
> month          12
> day            22
> svn rev        47281
> language       R
> version.string R version 2.8.1 (2008-12-22)
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.
>




More information about the R-help mailing list