From r.d.morey at rug.nl  Tue Apr  2 01:52:26 2013
From: r.d.morey at rug.nl (Richard D. Morey)
Date: Tue, 2 Apr 2013 01:52:26 +0200
Subject: [Rd] missing exported methods when compiling vignettes in R 3.0.0 RC
In-Reply-To: <mailman.11.1364810408.30516.r-devel@r-project.org>
References: <mailman.11.1364810408.30516.r-devel@r-project.org>
Message-ID: <1B1B843261D34A409EEE3DCAE737981E@rug.nl>

A new problem has cropped up with compiling vignettes for my package BayesFactor. I'm not sure when it started, but I can tell you it didn't occur on R 2.15.3, and it does on 3.0.0 RC (2013-03-31 r62463) (session info is at the bottom of this message).

I have defined methods for which.min and which.max for a class (I've defined both S3 and S4 methods for the class "BFBayesFactor") in my package. I've exported the S4 class using exportMethods, and declared the S3 method with S3method. You can see the NAMESPACE file here:

https://r-forge.r-project.org/scm/viewvc.php/pkg/BayesFactorPCL/NAMESPACE?view=markup&root=bayesfactorpcl

and the methods here:

https://r-forge.r-project.org/scm/viewvc.php/pkg/BayesFactorPCL/R/methods-BFBayesFactor.R?view=markup&root=bayesfactorpcl

I have code in a vignette that calls the which.max method on a BFBayesFactor object. However, when that happens as the vignette is being compiled, I get an error:

which.max(bf)
## Error: no method for coercing this S4 class to a vector



This also occurs with which.min, but oddly not any other method (including the is.na method, which is declared exactly the same way, as far as I can tell). This seems to imply that the which.min and which.max methods are not exported.

When I use double colon notation - which as I understand, only works with exported functions - it works (see below).

When I compile the Rmd file manually, I do not see this problem; I get no errors. This seems to be a problem unique to compiling the vignette. I've tried it in Rstudio, R from the command line, and using Rscript and calling knitr directly. It only occurs when building a vignette for the source package.

Steps to reproduce:
1. Check out latest version of BayesFactor package from R-forge (https://r-forge.r-project.org/scm/?group_id=554) (revision 320)

2. Create a source package (which compiles the vignette)

3. Open tar to see compiled vignette HTML (doc/manual.html - or, alternatively, see https://www.dropbox.com/s/6csznytp8i1akjl/manual.html). Search for second occurrence of "which.max", and see the following lines:

## which model index is the best? 
is(bf, "BFBayesFactor") 
## [1] TRUE 
BayesFactor::which.max(bf) 
## complaints 
## 1 
BayesFactor::which.min(bf) 
## critical + advance 
## 21 
which.max(bf) 
## Error: no method for coercing this S4 class to a vector 
which.min(bf) 
## Error: no method for coercing this S4 class to a vector 



I've been pulling my hair out on this, especially because something seems to have changed over the past few weeks that caused this, but I didn't catch exactly when, and I don't know if the issue lies with R 3.0.0 or my package.

> sessionInfo()
R version 3.0.0 RC (2013-03-31 r62463)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
locale:
[1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base 
other attached packages:
[1] BayesFactor_0.9.5 markdown_0.5.4 knitr_1.1.6 coda_0.16-1 lattice_0.20-15 
loaded via a namespace (and not attached):
[1] digest_0.6.3 evaluate_0.4.3 formatR_0.7 grid_3.0.0 mvtnorm_0.9-9994
[6] pbapply_1.0-5 stringr_0.6.2 tools_3.0.0  




Any help would be greatly appreciated,
Richard



[Rd] missing exported methods when compiling vignettes in R 3.0.0 RC
Richard D. Morey