Re: [R] adding a function after package.skeleton()

From: baptiste Auguié <ba208_at_exeter.ac.uk>
Date: Sun, 30 Dec 2007 20:28:09 +0000

Hi,

Thanks for this tip, I'm always amazed at the number of clever functions built-in in R –– just wish i could think of their name rather than reinventing the wheel.

However, I'm still stupidly stuck with this basic question: how should a function access data in its own package?

On 30 Dec 2007, at 18:27, Gabor Grothendieck wrote:

> On Dec 30, 2007 1:19 PM, baptiste Auguié <ba208@exeter.ac.uk> wrote:
>
>> These two functions use the dataframe "Constants", part of this
>> package:
>>
>>> `L2eV` <- function(lambda)
>>> {
>>> data("Constants")
>>> Constants$h*Constants$cel/Constants$ee/lambda ->eV
>>> eV
>>> }
>>
>
> This does not answer your question but note that you can do this:
>
> with(Constants, h * cel / ee / lambda)

Initial post:

>> From: ba208_at_exeter.ac.uk
>> Subject: adding a function after package.skeleton()
>> Date: 30 December 2007 18:19:40 GMT
>> To: r-help_at_r-project.org
>>
>> Dear R helpers,
>>
>> I've successfully created a package 'constants' using
>> package.skeleton() with one dataframe and a few functions.
>> However, now that I want to add some functions and data to the
>> package, I run into a problem.
>>
>> I ran prompt(...) and moved + edited the resulting .Rd files as
>> appropriate (I believe). The log file from RCMD check constants
>> does indicate a few problems (full log below).
>>
>> As far as I understand, the real problem would be on the lines:
>>
>>
>>> * checking R code for possible problems ... NOTE
>>> L2eV: no visible binding for global variable 'Constants'
>>> eV2L: no visible binding for global variable 'Constants'
>>>
>>
>>
>> These two functions use the dataframe "Constants", part of this
>> package:
>>
>>
>>> `L2eV` <- function(lambda)
>>> {
>>> data("Constants")
>>> Constants$h*Constants$cel/Constants$ee/lambda ->eV
>>> eV
>>> }
>>>
>>
>>
>> and
>>
>>
>>> `eV2L` <- function(eV)
>>> {
>>> data("Constants")
>>> Constants$h*Constants$cel/Constants$ee/eV ->Lambda
>>> Lambda
>>> }
>>>
>>
>>
>> After searching the R archives about "no visible binding for
>> global variable ", I added the quotes around "Constants" but it
>> doesn't seem to help. What would be the correct way to use this
>> data inside the package?
>>
>> Best regards,
>>
>> baptiste
>>
>> ----------------
>> Log of R CMD check constants :
>>
>>
>>
>>>
>>> baptiste-auguies-ibook-g4:~ baptiste$ R CMD check constants
>>> * checking for working latex ... OK
>>> * using log directory '/Users/baptiste/constants.Rcheck'
>>> * using R version 2.6.1 (2007-11-26)
>>> * checking for file 'constants/DESCRIPTION' ... OK
>>> * checking extension type ... Package
>>> * this is package 'constants' version '1.0'
>>> * checking package dependencies ... OK
>>> * checking if this is a source package ... OK
>>> * checking whether package 'constants' can be installed ... OK
>>> * checking package directory ... OK
>>> * checking for portable file names ... OK
>>> * checking for sufficient/correct file permissions ... OK
>>> * checking DESCRIPTION meta-information ... OK
>>> * checking top-level files ... OK
>>> * checking index information ... OK
>>> * checking package subdirectories ... OK
>>> * checking R files for non-ASCII characters ... OK
>>> * checking R files for syntax errors ... OK
>>> * checking whether the package can be loaded ... OK
>>> * checking whether the package can be loaded with stated
>>> dependencies ... OK
>>> * checking for unstated dependencies in R code ... OK
>>> * checking S3 generic/method consistency ... OK
>>> * checking replacement functions ... OK
>>> * checking foreign function calls ... OK
>>> * checking R code for possible problems ... NOTE
>>> L2eV: no visible binding for global variable 'Constants'
>>> eV2L: no visible binding for global variable 'Constants'
>>> * checking Rd files ... WARNING
>>> Rd files with non-standard keywords:
>>> L2eV.Rd: kwd1 kwd2
>>> constants-package.Rd: physical constants optical
>>> delete.all.Rd: kwd1 kwd2
>>> eV2L.Rd: kwd1 kwd2
>>> epsilon2nk.Rd: kwd1 kwd2
>>> fano.Rd: kwd1 kwd2
>>> lorentz.Rd: kwd1 kwd2
>>> nk2epsilon.Rd: kwd1 kwd2
>>> Each '\keyword' entry should specify one of the standard keywords
>>> (as
>>> listed in file 'KEYWORDS' in the R documentation directory).
>>>
>>> See the chapter 'Writing R documentation files' in manual 'Writing R
>>> Extensions'.
>>> * checking Rd cross-references ... OK
>>> * checking for missing documentation entries ... OK
>>> * checking for code/documentation mismatches ... OK
>>> * checking Rd \usage sections ... OK
>>> * checking data for non-ASCII characters ... OK
>>> * creating constants-Ex.R ... OK
>>> * checking examples ... OK
>>> * creating constants-manual.tex ... OK
>>> * checking constants-manual.tex ... OK
>>>
>>> WARNING: There was 1 warning, see
>>> /Users/baptiste/constants.Rcheck/00check.log
>>> for details
>>>


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. Received on Sun 30 Dec 2007 - 20:30:42 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 30 Dec 2007 - 21:30:22 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.