3

My problem is essentially the same as outlined in this unanswered question that resulted in a filed, and successfully closed bug report.

Given an existing S4 generic, in my case diag and diag<-, I wish to export an implementation for an S4 class from another package.

Reading through another thread I have discovered that i can successfully export these functions if I use the tags @exportMethod diag<- and @exportMethod diag respectively, but I can't get the documentation to work.

The first thread and subsequent closed bug report, suggests that the following should work (in this case for the method show):

#' @export
#' @aliases show,myPkgSpClass-method
#' @rdname myPkgSpClass-class
setMethod("show", "myPkgSpClass", function(object){ show(NA) })

However when I try to do the following for diag, I get an error when i try to build:

#' @export
#' @aliases diag<-,big.matrix-method
#' @rdname bigmatrix-diag
setMethod("diag<-", signature("big.matrix"), function(x, value) {
  SetDiag(x@address, value) # C++ implementation
  x
})

#' @export
#' @aliases diag,big.matrix-method
#' @rdname bigmatrix-diag
setMethod("diag", signature("big.matrix"), function(x) {
  GetDiag(x@address) # C++ implementation
})

The error: Error : Sections \title, and \name must exist and be unique in Rd files.

Clarification: Currently no implementation of diag is available for this class.

EDIT: Resolving the error: I can resolve this error, but not without clobbering the existing documentation for diag.

If I add a unique name and title as follows it will successfully builds:

#' @name diag
#' @title Extract and Replace the diagonal from a big.matrix
#' @aliases diag<-,big.matrix-method
#' @docType methods
#' @exportMethod diag<-
#' @rdname bigmatrix-diag
setMethod("diag<-", signature("big.matrix"), function(x, value) {
  SetDiag(x@address, value)
  x
})

#' @name diag
#' @title Extract and Replace the diagonal from a big.matrix.
#' @aliases diag,big.matrix-method
#' @docType methods
#' @exportMethod diag
#' @rdname bigmatrix-diag
setMethod("diag", signature("big.matrix"), function(x) {
  GetDiag(x@address)
})

But when i type ?diag in an R session I get the error:

Error in (function (path, query, ...) : replacement has length zero

Which i think means its finding two helpfiles fordiag`.

Community
  • 1
  • 1
Scott Ritchie
  • 10,293
  • 3
  • 28
  • 64

1 Answers1

2

Could you try this ?

#' @name diag
#' @aliases diag,big.matrix-method
#' @export diag
#' @rdname bigmatrix-diag
setMethod("diag", signature("big.matrix"), function(x) {
  GetDiag(x@address) # C++ implementation
})
Karl Forner
  • 4,175
  • 25
  • 32
  • See update in original question. I can get past that error, but not without clobbering the existing documentation for `diag`. – Scott Ritchie Sep 05 '13 at 00:32
  • Ok, try the alias, I mean the full name in the @name then. – Karl Forner Sep 05 '13 at 16:45
  • It compiles, but I'm not able to access the documentation. I'm also really unsure what the end result should look like in my case in terms of successfully linking the documentation. – Scott Ritchie Sep 05 '13 at 22:07
  • in the documentation, go to the list of packages, click on yours, you should see your method listed as "diag,big.matrix-method" or something like this – Karl Forner Sep 06 '13 at 07:52
  • 2
    I don't see it listed under `?diag`, I can only locate the documentation if i type `??\`diag,big.matrix-method\`` – Scott Ritchie Sep 06 '13 at 22:34