From hb at biostat.ucsf.edu  Fri Apr  6 23:15:01 2012
From: hb at biostat.ucsf.edu (Henrik Bengtsson)
Date: Fri, 6 Apr 2012 14:15:01 -0700
Subject: [Rd] R CMD check returns NOTE about package data set as global
	variable
In-Reply-To: <027098F6-E168-469F-B5A8-D3667EC39A63@gmail.com>
References: <1114888490.18258021.1333740833420.JavaMail.root@jaguar9.sfu.ca>
	<4F7F50A5.7090304@fhcrc.org>
	<027098F6-E168-469F-B5A8-D3667EC39A63@gmail.com>
Message-ID: <CAFDcVCTcJiNSnP9mqACV7p74jn-8i26=mOJG4Nf+ANUdfPFOtQ@mail.gmail.com>

On Fri, Apr 6, 2012 at 1:33 PM, peter dalgaard <pdalgd at gmail.com> wrote:
>
> On Apr 6, 2012, at 22:23 , Herv? Pag?s wrote:
>
>> On 04/06/2012 12:33 PM, Brad McNeney wrote:
>>> OK, thanks for the tip on good coding practice. I'm still getting the NOTE though when I make the suggested change.
>>
>> Because when you do return(RutgersMapB36[,1]), the code checker has no
>> way to know that the RutgersMapB36 variable is actually defined.
>>
>> Try this:
>>
>> test<-function() {
>> ? RutgersMapB36 <- NULL
>> ? data(RutgersMapB36)
>> ? return(RutgersMapB36[,1])
>> }
>>
>
> That might remove the NOTE, but as far as I can see, it also breaks the code...

For data() per se, which by default clutter up the global environment,
you can do:

test<-function() {
  env <- new.env()
? data("RutgersMapB36", envir=env)
? env$RutgersMapB36[,1]
}

That is more explicit, and I do believe you won't get a NOTE about it.

Other than that, one can also use the following style (which still
seems to do the trick) for data(), attach(), load() et al., iff have
to use them:

test<-function() {
  # To avoid NOTEs by R CMD check
? RutgersMapB36 <- NULL; rm(RutgersMapB36);

? data(RutgersMapB36)
? return(RutgersMapB36[,1])
}


/Henrik

>
> --
> Peter Dalgaard, Professor,
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Email: pd.mes at cbs.dk ?Priv: PDalgd at gmail.com
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] R CMD check returns NOTE about package data set as global variable
Henrik Bengtsson