Giles Hooker
2009-Aug-28 01:12 UTC
[Rd] R CMD check does not recognize S4 functions inside other functions?
I am developing a new R package and am now checking it for submission to CRAN. The some functions in the package make use of the sparse matrix routines in the package 'Matrix'. When these are loaded in R, they create no problems. However, when running R CMD check, I run into the following error in executing the examples in a .rd file: > DD = Matrix(diag(1,200),sparse=TRUE) > tDD = t(DD) > > fres = FitMatchOpt(coefs=coefs,which=2,pars=pars,proc) Error in t.default(DD) : argument is not a matrix Calls: FitMatchOpt -> t -> t.default Execution halted The first two lines of the function FitMatchOpt are DD = Matrix(diag(1,200),sparse=TRUE) tDD = t(DD) These were fine when given in the examples section of the .rd file directly. However, when defined within a function in the package, the lines cause an error. Sparse matrices improve the computational efficiency of the routines I am developing and I would like to use them. But I'm not sure how I can get around this error. Many thanks, Giles Hooker
Sylvain Loiseau
2009-Aug-28 07:10 UTC
[Rd] R CMD check does not recognize S4 functions inside other functions?
It looks as if it is very related to the message I posted just some day ago ("Problem with standard generic methods in Matrix package"). Sylvain On Fri, 28 Aug 2009 03:12:48 +0200, Giles Hooker <gjh27 at cornell.edu> wrote:> I am developing a new R package and am now checking it for submission to > CRAN. > > The some functions in the package make use of the sparse matrix routines > in the package 'Matrix'. > > When these are loaded in R, they create no problems. > > However, when running R CMD check, I run into the following error in > executing the examples in a .rd file: > > > DD = Matrix(diag(1,200),sparse=TRUE) > > tDD = t(DD) > > > > fres = FitMatchOpt(coefs=coefs,which=2,pars=pars,proc) > Error in t.default(DD) : argument is not a matrix > Calls: FitMatchOpt -> t -> t.default > Execution halted > > The first two lines of the function FitMatchOpt are > > DD = Matrix(diag(1,200),sparse=TRUE) > tDD = t(DD) > > These were fine when given in the examples section of the .rd file > directly. However, when defined within a function in the package, the > lines cause an error. > > Sparse matrices improve the computational efficiency of the routines I > am developing and I would like to use them. But I'm not sure how I can > get around this error. > > Many thanks, > > Giles Hooker > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel
Martin Maechler
2009-Aug-28 07:58 UTC
[Rd] R CMD check does not recognize S4 functions inside other functions?
>>>>> "GH" == Giles Hooker <gjh27 at cornell.edu> >>>>> on Thu, 27 Aug 2009 21:12:48 -0400 writes:GH> I am developing a new R package and am now checking it for submission to GH> CRAN. GH> The some functions in the package make use of the sparse matrix routines GH> in the package 'Matrix'. GH> When these are loaded in R, they create no problems. GH> However, when running R CMD check, I run into the following error in GH> executing the examples in a .rd file: >> DD = Matrix(diag(1,200),sparse=TRUE) >> tDD = t(DD) {{well, the transpose of a diagonal matrix, really ??}} Just a remark: For larger values of n=200, it would be more efficient (and elegant) to directly use DD <- Diagonal(200) See ?Diagonal, and e.g., > Diagonal(4) 4 x 4 diagonal matrix of class "ddiMatrix" [,1] [,2] [,3] [,4] [1,] 1 . . . [2,] . 1 . . [3,] . . 1 . [4,] . . . 1 > .symDiagonal(4) 4 x 4 sparse Matrix of class "dsCMatrix" [1,] 1 . . . [2,] . 1 . . [3,] . . 1 . [4,] . . . 1 >> >> fres = FitMatchOpt(coefs=coefs,which=2,pars=pars,proc) GH> Error in t.default(DD) : argument is not a matrix GH> Calls: FitMatchOpt -> t -> t.default GH> Execution halted GH> The first two lines of the function FitMatchOpt are GH> DD = Matrix(diag(1,200),sparse=TRUE) GH> tDD = t(DD) GH> These were fine when given in the examples section of the .rd file GH> directly. However, when defined within a function in the package, the GH> lines cause an error. How does your package "get Matrix"? I'm sure there's some problem in requiring Matrix, in either your DESCRIPTION or your NAMESPACE (or a .First.library or ...) Your DESCRIPTION should have Depends: ...., Matrix Imports: ...., Matrix and your NAMESPACE either importFrom("Matrix", .....)# the things you need or (if you use many things from the Matrix package, and/or in some way just *extend* it ...) import("Matrix") Does that help? Best regards, Martin Maechler GH> Sparse matrices improve the computational efficiency of the routines I GH> am developing and I would like to use them. But I'm not sure how I can GH> get around this error. GH> Many thanks, GH> Giles Hooker GH> ______________________________________________ GH> R-devel at r-project.org mailing list GH> https://stat.ethz.ch/mailman/listinfo/r-devel