Dear all, Happy new year! I posted a very similar question a few days ago, but probably too cluttered. Here is a tidy, minimal version: I want to make a package, with a data.frame d and a function f given below. Now, the function f needs to use the data.frame d. I could (and that's what I've done temporarily) make a local duplicate of this data.frame in the function definition, but it seems silly. I've tried "attach()", "data()", but both fail when running R CMD check with the error> * checking R code for possible problems ... NOTE > f: no visible binding for global variable 'd'Here is the minimal package skeleton:> d <- data.frame(a=1) > > f <- function(x) > { > data("d") > x+d$a > } > > package.skeleton(list=c("f","d"), name="mypkg")What would be a sensible way to refer to this data inside the package? Best regards, baptiste _____________________________ Baptiste Augui? Physics Department University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag http://projects.ex.ac.uk/atto
baptiste Augui? wrote:> Dear all, > > Happy new year! > > I posted a very similar question a few days ago, but probably too > cluttered. Here is a tidy, minimal version: > > I want to make a package, with a data.frame d and a function f given > below. Now, the function f needs to use the data.frame d. I could > (and that's what I've done temporarily) make a local duplicate of > this data.frame in the function definition, but it seems silly. > > I've tried "attach()", "data()", but both fail when running R CMD > check with the error > >> * checking R code for possible problems ... NOTE >> f: no visible binding for global variable 'd'This is just a note, you can either ignore it or use a dirty trick to circumvent Luke's checks by d <- get("d") Perhaps it is better to get from the correct environment by specifying it. Uwe> Here is the minimal package skeleton: > >> d <- data.frame(a=1) >> >> f <- function(x) >> { >> data("d") >> x+d$a >> } >> >> package.skeleton(list=c("f","d"), name="mypkg") > > > What would be a sensible way to refer to this data inside the package? > > Best regards, > > baptiste > > _____________________________ > > Baptiste Augui? > > Physics Department > University of Exeter > Stocker Road, > Exeter, Devon, > EX4 4QL, UK > > Phone: +44 1392 264187 > > http://newton.ex.ac.uk/research/emag > http://projects.ex.ac.uk/atto > > ______________________________________________ > 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.
then combine system.file() with load(). b On Jan 20, 2008, at 3:40 PM, Dan Kelley wrote:> > Yes, data() works, but then I have this warning from "R CMD check" > on my > package, so I think I should not be doing it that way. > > > > Benilton Carvalho wrote: >> >> have you tried >> data() >> instead? >> b >> >> >> > > -- > View this message in context: http://www.nabble.com/access-data-inside-package-tp14565386p14986576.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.
hits=-2.6 tests=BAYES_00 X-USF-Spam-Flag: NO First call data("d") then everything is fine already - except that codetools are moaning around. Those codetools can be calmed down by the line we had already: d <- get("d", pos=globalenv()) Uwe Ligges Dan Kelley wrote:> Yes, data() works, but then I have this warning from "R CMD check" on my > package, so I think I should not be doing it that way. > > > > Benilton Carvalho wrote: >> have you tried >> data() >> instead? >> b >> >> >> >
Thanks, Uwe, this works perfectly. Uwe Ligges-3 wrote:> > hits=-2.6 tests=BAYES_00 > X-USF-Spam-Flag: NO > > > First call > > data("d") > > then everything is fine already - except that codetools are moaning > around. Those codetools can be calmed down by the line we had already: > > d <- get("d", pos=globalenv()) > > Uwe Ligges > > > > Dan Kelley wrote: >> Yes, data() works, but then I have this warning from "R CMD check" on my >> package, so I think I should not be doing it that way. >> >> >> >> Benilton Carvalho wrote: >>> have you tried >>> data() >>> instead? >>> b >>> >>> >>> >> > > ______________________________________________ > 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. > >-- View this message in context: http://www.nabble.com/access-data-inside-package-tp14565386p14987387.html Sent from the R help mailing list archive at Nabble.com.