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

baptiste Auguié ba208 at exeter.ac.uk
Sun Dec 30 21:28:09 CET 2007


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 at 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



More information about the R-help mailing list