[Roxygen-devel] setReplaceMethod problems

Janssen, B.J. B.J.Janssen at tue.nl
Thu Jul 22 17:42:37 CEST 2010


Hello,

I am writing a package in R using S4 classes and had problems with roxygen when I tried to include a setReplaceMethod for one of my classes.  Roxygen 0.1-2 revision 245 crashed whenever a setReplaceMethod declaration was encountered. Searching the net got me to <https://r-forge.r-project.org/tracker/index.php?func=detail&aid=842&group_id=183&atid=1500> which confirms it is not (yet) supported by roxygen.

Installing the latest revision from svn (248) solved the crashing problem for me. It still produced a warning because "setReplaceMethod" was not recognized. This can be resolved by the patch included below. It just applies the same method as setMethod does to any setReplaceMethod encountered. The disadvantage is that it cannot handle duplicate naming. For example, it overwrites "[.Rd" if  both  a setMethod and a setReplaceMethod are declared for "[". These filenames should get renamed to something more sensible…

Regards,
Bart

> svn diff Rd2.R 
Index: Rd2.R
===================================================================
--- Rd2.R	(revision 248)
+++ Rd2.R	(working copy)
@@ -55,6 +55,14 @@
                               formals=S4formals$definition)
                        })
 
+register.srcref.parser('setReplaceMethod',
+                       function(pivot, expression) {
+                         S4formals <- parseS4.method(cdr(expression))
+                         list(S4method=car(expression),
+                              S4formals=S4formals,
+                              formals=S4formals$definition)
+                       })
+
 #' New implementation of the Rd roclet; same functionality as the original
 #' implementation plus basic S4 handling.
 #'



More information about the Roxygen-devel mailing list