Re: [Rd] Creating an S3 method when the generic function is defined in another (imported) package

2010-05-16 Thread Arne Henningsen
On 14 May 2010 10:37, Achim Zeileis  wrote:
> On Fri, 14 May 2010, Arne Henningsen wrote:
>> In one of my packages (maxLik), I would like to add an S3 method,
>> where the generic function (estfun) is defined in another package
>> (sandwich). Everything works fine if my package "Depends" on the other
>> package and I import the generic function "estfun" from the "sandwich"
>> package and define the new method in the NAMESPACE file. However, I
>> prefer not to load the entire other package just to use a single
>> generic function from it. Therefore, I replaced "Depends" by "Imports"
>> in the DESCRIPTION file and (re-)exported "estfun" in the NAMESPACE
>> file. Now "R CMD check" warns about the undocumented code object
>> "estfun" but I do not want to include a duplicate of the documentation
>> of "estfun". Do you know a better solution?
>
> I probably wouldn't re-export the estfun() generic. People will probably
> load "sandwich" anyway before calling estfun(), in particular if they want
> to compute the sandwich() covariance matrix.

That's certainly the best solution for this issue Thanks!
However, I have basically the same problem in another package, where
the method can be (reasonably) applied without loading the package, in
which the generic function is defined. Hence, requiring that the user
loads the other package "by hand" is no solution here. So is there a
better solution than making my package *depend* on the other package
or including a duplicate of the documentation of the generic function?

Thanks a lot,
/Arne

-- 
Arne Henningsen
http://www.arne-henningsen.name

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] R CMD check

2010-05-16 Thread sahil seth
Hi,
I have been finding clues on the internet to understand the reason for this 
warning.
The package i have made, builds, installs and works well, except for this 
warning when I check it:

When I run:
R CMD check mypack_1.0.tar.gz
... ... .. ..
* checking R code for possible problems ... NOTE
Found possibly global 'T' or 'F' in the following functions:
  HWE procRef readMartFile readPhase2File
.. ... .. 



I have several other functions in the package, but the warning is for this 
subset. 

I am trying to find a common thing within this subset, and cant figure out one 
to go after it.

Thanks a lot for the help.


Regards,
Sahil Seth

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] R CMD check

2010-05-16 Thread Peter Dalgaard
sahil seth wrote:
> Hi,
> I have been finding clues on the internet to understand the reason for this 
> warning.
> The package i have made, builds, installs and works well, except for this 
> warning when I check it:
> 
> When I run:
> R CMD check mypack_1.0.tar.gz
> ... ... .. ..
> * checking R code for possible problems ... NOTE
> Found possibly global 'T' or 'F' in the following functions:
>   HWE procRef readMartFile readPhase2File
> .. ... .. 
> 
> 
> 
> I have several other functions in the package, but the warning is for this 
> subset. 
> 
> I am trying to find a common thing within this subset, and cant figure out 
> one to go after it.
> 
> Thanks a lot for the help.

Look for spots where you sloppily have used, say, na.rm=T instead of
na.rm=TRUE.

This kind of construction will break if something redefines T/F
globally, hence the warning. (The code checker heuristics first looks a
local definition of T or F, in which case things are fine, or at least
not wrong for this particular reason.)

-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] format.data.frame containing S4 class with format method

2010-05-16 Thread Daniel Murphy
Hi again,

I must be misunderstanding something fundamental about how an S4 class
stored in a data.frame can be persuaded to print according to a desired
format. The help page says:

format.data.frame formats the data frame column by column, applying the
appropriate method of format for each column.

Here is my class:
> setClass("A",contains="character")
[1] "A"
> a <- new("A", "aaa")
> a
An object of class "A"
[1] "aaa"

I defined my format method to display in uppercase:
> setMethod("format","A", function(x, ...) toupper(x))
[1] "format"
> format(a)
An object of class "A"
[1] "AAA"

I looked at the S4 class definition for data.frame (getClass("data.frame"))
which prompted me to store the instance 'a' into a data.frame as follows:
> adf<-new("data.frame",list(a), names="a", row.names="1")
> adf
Object of class "data.frame"
a
1 aaa

... not upper case. The str function clearly shows that the object was
successfully stored in the data.frame:
> str(adf)
'data.frame':   1 obs. of  1 variable:
'data.frame':   1 obs. of  1 variable:
Formal class 'data.frame' [package "methods"] with 4 slots
  ..@ .Data:List of 1
  .. ..$ :Formal class 'A' [package ".GlobalEnv"] with 1 slots
  .. .. .. ..@ .Data: chr "aaa"
  ..@ names: chr "a"
  ..@ row.names: chr "1"
  ..@ .S3Class : chr "data.frame"

Is there another step I should be taking so that "A"'s format method is
found and used?

Thank you,

Dan Murphy

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel